[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 582
  • Last Modified:

Disable Macro

I use Excel.Application object to open excel file in VB, If excel file has a macro, i want to disable it, How can I do?

Thank you.
0
melodiesoflife
Asked:
melodiesoflife
1 Solution
 
Andre412Commented:
Are you using WorkBooks.Open? I looked in the object browser at this and the only reference to macros is that Auto_Open macros will not run when WorkBooks.Open is used.
0
 
DocMCommented:

Application.EnableEvents = False
     
Workbooks.Open Filename:="C:\Mes documents\book1.xls"
   
Application.EnableEvents = True
0
 
DocMCommented:
Sorry. This is code for VBA. Not for Automation.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
DocM, you code is however correct?!

dim appExcel as Excel.Application
---
appExcel.EnableEvents = False
appExcel.workbooks.Open Filename:="C:\Mes documents\book1.xls"
appExcel.EnableEvents = True
0
 
melodiesoflifeAuthor Commented:
Thank Angellll, Some ones suggested me to do that, I try it, but this way can not disable macro. Do you have another way?
0
 
melodiesoflifeAuthor Commented:
In fact, almost macro will be disable if you use that method, but if there is a macro action when workbook open, for example:

Private Sub Workbook_Open()
    MsgBox "Can not be disable with EnableEvents"
End Sub

A macro like that can not be disable if you use EnableEvents flag.
0
 
DocMCommented:
In a Workbook named DisableEvents.xls, enter:

Private Sub Workbook_Open()
 Application.EnableEvents = False
End Sub

In VB, call that Workbook first to disable the events :

Dim appExcel As New Excel.Application

appExcel.Workbooks.Open filename:="C:\My documents\DisableEvents.xls"

'The Auto_Open event will be ignored
appExcel.Workbooks.Open filename:="C:\My documents\book1.xls"

appExcel.Visible = True
Set appExcel = Nothing
0
 
melodiesoflifeAuthor Commented:
OK,
But if I don't want to open a temporary file as DisableEvents.xls. Do you have another way?
0
 
DocMCommented:
No. This a security feature and one cannot circumvent a security feature even from VB.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now