Hello all,
I'm definitely very green when it comes to both coding macros and vb, so I'm having a difficult time with something I'm hoping is relatively easy (maybe just properly implementing a try/catch?) The code is as follows:
Basically the script refreshes a few tables - the one problem happens on this line: Selection.QueryTable.Refresh BackgroundQuery:=False
That brings up a file dialog, and if the user cancels instead of choosing a file to import, a run-time error 1004 is thrown. Any ideas on how to prevent that error from being thrown, and instead stop the script from executing any further (or just ignore the error...)
Any help would be greatly appreciated!
I'm definitely very green when it comes to both coding macros and vb, so I'm having a difficult time with something I'm hoping is relatively easy (maybe just properly implementing a try/catch?) The code is as follows:
Code:
Sub TestMacro()
'
' TestMacro Macro
'
'
Sheets("Data").Select
Range("B15").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Source SAP Data").Select
Range("A14").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable1").PivotSelect _
"'[Project Code].[Project Code]'[All]", xlLabelOnly + xlFirstRow, True
Sheets("SFDC to OLAP Comparison").Select
Range("C8").Select
ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
End Sub
Basically the script refreshes a few tables - the one problem happens on this line: Selection.QueryTable.Refresh BackgroundQuery:=False
That brings up a file dialog, and if the user cancels instead of choosing a file to import, a run-time error 1004 is thrown. Any ideas on how to prevent that error from being thrown, and instead stop the script from executing any further (or just ignore the error...)
Any help would be greatly appreciated!