Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I turn off macros when programmatically opening a workbook.

Hi,
I'm trying to turn off a macro that runs when I open a workbook
programmatically. I'm not sure how to do this. I want to do
(programmatically) the equivalent of pressing the 'Disable macros' button
when I open this program. I have workarounds if this doesn't work, but would
like to do something quick and easy!

Thanks!
Phil
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default How do I turn off macros when programmatically opening a workbook.

Phil

If you're auto macros are of the AutoOpen variety, they won't execute when
you open a workbook via code. If they are events like Workbook_Open, then

Application.EnableEvents = False
Workbooks.Open etc..
Application.EnableEvents = True

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

PhilBerkhof wrote:
Hi,
I'm trying to turn off a macro that runs when I open a workbook
programmatically. I'm not sure how to do this. I want to do
(programmatically) the equivalent of pressing the 'Disable macros'
button when I open this program. I have workarounds if this doesn't
work, but would like to do something quick and easy!

Thanks!
Phil



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default How do I turn off macros when programmatically opening a workbook.

Private Sub Workbook_Open()

End Sub
Above is where the macro is running from. If you do not want it to rum,
remove the code. You can put it some where else to make it available to run.


"PhilBerkhof" wrote:

Hi,
I'm trying to turn off a macro that runs when I open a workbook
programmatically. I'm not sure how to do this. I want to do
(programmatically) the equivalent of pressing the 'Disable macros' button
when I open this program. I have workarounds if this doesn't work, but would
like to do something quick and easy!

Thanks!
Phil

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default How do I turn off macros when programmatically opening a workbook.

Phil,
The code I have placed below came from some kind soul posted on this
UseNet. When the Workbook_Open procedure runs upon opening the file--we
will call the child document--this code will look to see if the file
name you supply is open--lets call it the parent document. If the
parent document is open it will exit the Workbook_Open procedure.

1. Paste the line of code mentioned below in your Workbook_Open
procedure located in the code for 'ThisWorkbook'; change the file name.

2. Next Paste the TestWorkbookOpen function below the end of the
Workbook_Open procedure.


Public Sub Workbook_Open()
Application.ScreenUpdating = False

'1. Place this line of code in your workbook_open procedure...
If TestWorkbookOpen("TheParentFileName.xls") Then Exit Sub

'Your code here...
Application.ScreenUpdating = True
End Sub

' 2. Next Paste the TestWorkbookOpen function below the end of the
Workbook_Open procedure.
Function TestWorkbookOpen(WorkBookName As String) As Boolean
' returns TRUE if the workbook is open
TestWorkbookOpen = False

On Error GoTo WorkBookNotOpen
If Len(Application.Workbooks(WorkBookName).Name) 0 Then
TestWorkbookOpen = True
Exit Function
End If

WorkBookNotOpen:
End Function

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable macros on a programmatically opening .xls file Matt[_2_] Excel Discussion (Misc queries) 2 May 25th 07 04:45 AM
Disable Macros when opening workbook Rob[_21_] Excel Programming 7 November 12th 04 09:22 AM
Turn Off Macros With Workbook Open Paul Moles Excel Programming 8 October 19th 04 08:01 AM
Open workbook-macros enabled, opening another with macros George J Excel Programming 5 September 17th 04 02:07 PM
Opening a workbook containing macros from VB Brian Walters Excel Programming 2 August 6th 03 10:20 PM


All times are GMT +1. The time now is 01:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"