JumboCactuar
Well-known Member
- Joined
- Nov 16, 2016
- Messages
- 788
- Office Version
- 365
- Platform
- Windows
Hi,
i have this VBA script to load data from another sheet but the sheets i load from contain Workbook_Open macros. Whenever i run the script the macro is triggered
Is there a way to prevent this?
My code below loads up file explorer, i click on my source workbook and it opens
Msgbox pops up from the source Workbook_Open macro (trying to prevent this)
DisplayAlerts.False doesnt work for this
any help appreciated
i have this VBA script to load data from another sheet but the sheets i load from contain Workbook_Open macros. Whenever i run the script the macro is triggered
Is there a way to prevent this?
My code below loads up file explorer, i click on my source workbook and it opens
Msgbox pops up from the source Workbook_Open macro (trying to prevent this)
DisplayAlerts.False doesnt work for this
Code:
Sub LoadData()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim FileName As String
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim ActiveListWB As Workbook
ChDrive Range("D2").Value
ChDir Range("D3").Value
Set WS1 = ActiveWorkbook.Sheets("Data")
FileName = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*),*.xls*", _
Title:="Select Timesheet to Import", _
MultiSelect:=False)
If FileName = "False" Then
Exit Sub
Else
Set ActiveListWB = Workbooks.Open(FileName)
End If
Set WS2 = ActiveListWB.Sheets("SourceData")
WS2.Range("A2:A1000").Copy WS1.Range("A2")
ActiveWorkbook.Close False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
any help appreciated