Tôi không biết tại sao điều này không được đề cập rõ ràng trong các câu trả lời khác nhưng tôi đã tìm thấy Application.AutomationSecurity
để thực hiện chính xác những gì được yêu cầu. Về cơ bản
Application.AutomationSecurity = msoAutomationSecurityByUI
'This is the default behavior where each time it would ask me whether I want to enable or disable macros
Application.AutomationSecurity = msoAutomationSecurityForceDisable
'This would disable all macros in newly opened files
Application.AutomationSecurity = msoAutomationSecurityLow
'This would enable all macros in newly opened files
Ngay cả sau khi mã được chạy, cài đặt sẽ không hoàn nguyên về hành vi mặc định, do đó bạn cần phải thay đổi lại. Do đó cho câu hỏi này
Application.AutomationSecurity = msoAutomationSecurityForceDisable
' Your code
Application.AutomationSecurity = msoAutomationSecurityByUI
Nguồn
2017-10-29 05:18:28
Bạn luôn có thể đặt bảo mật macro để chặn tất cả các macro. Điều này có lẽ không lý tưởng, nhưng nên làm những gì bạn đang yêu cầu. – Gaffi