?
Solved

Disable Macro

Posted on 2003-03-07
9
Medium Priority
?
581 Views
Last Modified: 2012-05-04
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
Comment
Question by:melodiesoflife
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 4

Expert Comment

by:Andre412
ID: 8087289
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
 
LVL 3

Expert Comment

by:DocM
ID: 8087762

Application.EnableEvents = False
     
Workbooks.Open Filename:="C:\Mes documents\book1.xls"
   
Application.EnableEvents = True
0
 
LVL 3

Expert Comment

by:DocM
ID: 8087959
Sorry. This is code for VBA. Not for Automation.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 8088043
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
 
LVL 6

Author Comment

by:melodiesoflife
ID: 8092143
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
 
LVL 6

Author Comment

by:melodiesoflife
ID: 8092196
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
 
LVL 3

Accepted Solution

by:
DocM earned 150 total points
ID: 8092197
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
 
LVL 6

Author Comment

by:melodiesoflife
ID: 8100271
OK,
But if I don't want to open a temporary file as DisableEvents.xls. Do you have another way?
0
 
LVL 3

Expert Comment

by:DocM
ID: 8100843
No. This a security feature and one cannot circumvent a security feature even from VB.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question