How do I ensure macro only can be executed upon the Book2 is open? The VBS code below will help to auto open the file upon data extraction but it will be delay a bit to open hence resulted error at 100. On Error function seems doesnt work. Im thinking is there any loop function to wait until the file is exist?
Code:
Sub Macro1()
With VBS data
VBS code 'This VBS will download data and extracted into Book2.'
End With
100
Windows("Book2.xlsx").Activate
On Error GoTo 100
Columns("F:F").Select
Selection.TextToColumns Destination:=Range("F1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Columns("T:T").Select
Selection.TextToColumns Destination:=Range("T1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Range("A:T").Select
Selection.Copy
Windows(Dir(ThisWorkbook.FullName)).Activate
Sheets("Book2").Select
Range("A1").Select
ActiveSheet.Paste
Application.DisplayAlerts = False
Workbooks("Book2.xlsx").Close savechanges:=False
Application.DisplayAlerts = True
End Sub