Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default stop auto macros running when opening a file by code

I need to copy some date out of some xl files, the trouble is they have
Workbook_Open macro's & Links to other files, and I can't figure out how to
open the files without being asked about upating the links, and then are the
Workbook_Open macro's going to give me greif?

How can I stop xl asking the questions?
These are the first lines of code...
fn & mth are supplied strings, for files I know exist

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False

On Error Resume Next
Set wbCVR = Workbooks(fn) 'Have I
got file open?
If wbCVR Is Nothing Then
'No - open it
On Error GoTo 0 'if not
able to open goto error
Workbooks.Open Filename:=".\" & mth & "\" & fn, ReadOnly:=True,
Notify:=False
Set ws = ActiveWorkbook.Worksheets("By Staff")
Else
wbCVR.Activate
'Yes - use it
Set ws = wbCVR.Worksheets("By Staff")
End If


TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default stop auto macros running when opening a file by code

With the .enableevents=false, you shouldn't have any trouble with any of the
events in the newly opened workbook.

And take a look at workbooks.open in VBA's help. You'll see an option
(Updatelinks:=0) that you can add to your line of code.

Graham Y wrote:

I need to copy some date out of some xl files, the trouble is they have
Workbook_Open macro's & Links to other files, and I can't figure out how to
open the files without being asked about upating the links, and then are the
Workbook_Open macro's going to give me greif?

How can I stop xl asking the questions?
These are the first lines of code...
fn & mth are supplied strings, for files I know exist

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False

On Error Resume Next
Set wbCVR = Workbooks(fn) 'Have I
got file open?
If wbCVR Is Nothing Then
'No - open it
On Error GoTo 0 'if not
able to open goto error
Workbooks.Open Filename:=".\" & mth & "\" & fn, ReadOnly:=True,
Notify:=False
Set ws = ActiveWorkbook.Worksheets("By Staff")
Else
wbCVR.Activate
'Yes - use it
Set ws = wbCVR.Worksheets("By Staff")
End If

TIA


--

Dave Peterson
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
How to stop running macros everytime I run excel? SusieOrtiz Excel Discussion (Misc queries) 1 August 18th 09 05:20 AM
How do I stop Excel from opening all files w/macros & running them BobC Excel Discussion (Misc queries) 4 April 5th 09 08:25 PM
Running Macros without opening file. [email protected] Excel Programming 2 January 28th 06 06:56 AM
Stop Macros from Running When Workbook Opened via Automation Google Boy of Company C Excel Programming 6 September 15th 05 04:39 PM
opening and running macros in an Excel file in a new instance of Excel Malone[_2_] Excel Programming 0 September 30th 03 01:58 AM


All times are GMT +1. The time now is 10:39 AM.

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

About Us

"It's about Microsoft Excel"