Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel automation: Suppressing an auto-run macro

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
I have some Visual FoxPro code that uses Automation to create an Excel workbook, based on a template. It's the usual sort of stuff:

Code:
loXL = CreateObject("excel.application")
loWB = loXL.Workbooks.Add("c:\stuff\MyTemplate.XLS")

The problem is that the template contains an auto-run macro, that is, a macro that is designed to run each time a user opens the workbook. The macro uses Excel's Workbook_Open(), which fires when the workbook is opened.

I want the macro to run when a user opens the workbook (in Excel), but it's also running when the above VFP code is executed, which I don't want.

Does anyone know of a way to suppress the auto-start macro in these circumstances?

Thanks in advance,

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 

To prevent Excel from not running auto-run macros on opening workbooks I think you will have to run Excel with the /automation or /safe parameter eg: Excel.exe /automation or Excel.exe /safe .

 
Mike,

Is this what you had in mind:

Code:
loXL = CreateObject("excel.application")
loXL.EnableEvents=.F.
loWB = loXL.Workbooks.Add("c:\stuff\MyTemplate.XLS")

I just tried that. Unfortunately, it didn't make any difference.

Thanks anyway for the suggestion.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mm0000,

Yes, I know that would prevent the macro running from within Excel. And you can also do it by holding down the Shift key when you open the workboook. But none of those methods would work from within Automation.

Thanks anyway for your reply.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top