![]() |
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 |
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 |
All times are GMT +1. The time now is 02:59 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com