Prevent an on open macro from running when retrieving data

Phanmore

Board Regular
Joined
Aug 7, 2009
Messages
116
Good Morning All,

I was wondering if anyone could help me.

I have a main spreadsheet that opens another spreadsheet, copies some information and pastes it in to my main sheet.

The problem is, the workbook I am retrieving the data from has quite lenghtly code under the on open event.

Is there any vba code that will allow me to open the 2nd spreadsheet and disble the on open event?

If that's not possible, is there any other simple way to retrieve the data without opening the workbook?


This is the code my main workbook currently runs.

Code:
Sub ComplianceImport()
Application.ScreenUpdating = False
 
Dim ReadOnlyWB As Workbook
Dim ActiveWB As Workbook
Dim Sht As Worksheet

Set ActiveWB = ActiveWorkbook
Sheets("Database").Visible = True
For Each Sht In ActiveWorkbook.Worksheets
If Sht.Name <> "Database" Then
Sht.Visible = False
End If
Next Sht

ActiveWB.Sheets("Import Data").Visible = True
ActiveWB.Sheets("Import Data").Cells.ClearContents
 

Set ReadOnlyWB = Workbooks.Open(Filename:="\\0788 Group\Availability & Compliance\Compliance Update.xls", ReadOnly:=True)
ReadOnlyWB.Sheets("Database").Visible = True
ReadOnlyWB.Sheets("Database").Select
ReadOnlyWB.Sheets("Database").Cells.Copy
ActiveWB.Activate
ActiveWB.Sheets("Import Data").Select
Range("A1").Select
ActiveSheet.Paste
Cells.Copy
ActiveCell.PasteSpecial Paste:=xlPasteValues
ReadOnlyWB.Activate
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Sheets("Database").Visible = True
Range("F2").Select
ActiveCell.Formula = "=IF(ISERROR(VLOOKUP(A2,'Import Data'!A:FE,161,FALSE)),""Not Imported"",VLOOKUP(A2,'Import Data'!A:FE,161,FALSE))"
ActiveCell.Copy
Range("J65536").End(xlUp).Offset(0, -4).Select
Range(ActiveCell, ActiveCell.End(xlUp)).Select
ActiveSheet.Paste
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("Import Data").Visible = False
Sheets("Checklist").Visible = False
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try like this

Code:
Application.EnableEvents = False
Set ReadOnlyWB = Workbooks.Open(Filename:="\\0788 Group\Availability & Compliance\Compliance Update.xls", ReadOnly:=True)
Application.EnableEvents = True
 
Upvote 0
Perfect Thanks.

The code doesn't run anymore, but it didn't speed it up as much as I'd thought it would. It may just be my netowrk :(
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,553
Members
452,928
Latest member
101blockchains

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top