stop auto macros running when opening a file by code

G

Guest

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
 
D

Dave Peterson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top