Hello everyone!
I'm having an issue closing a worksheet in my VBA code. I can open it just fine in VBA using wildcards but for some reason it won't close that same file. It gives me an error message "subscript out of range".
It's the Windows(MyFile).Close that creates the error. I know it has something to do with the wildcards but not sure what... any help would be great appreciated!!!
Here is my code:
I'm having an issue closing a worksheet in my VBA code. I can open it just fine in VBA using wildcards but for some reason it won't close that same file. It gives me an error message "subscript out of range".
It's the Windows(MyFile).Close that creates the error. I know it has something to do with the wildcards but not sure what... any help would be great appreciated!!!
Here is my code:
Code:
Sheets("2700 Cash Files").Select
Range("L1").Value = 1
Application.DisplayAlerts = False
Dim MyPath As String
Dim MyFile As String
MyPath = "C:\Users\User\Desktop\Export Files\"
MyInput = Application.InputBox("Enter Week Start Date (Format:MM-DD-YYYY)")
If MyInput = False Then End
If MyInput = "" Then End
Range("M1").Value = MyInput
MyFile = Range("N1") & "******_200100.cas"
ChDir MyPath & MyInput
Workbooks.OpenText Filename:=MyFile _
, Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, Tab:=True, Comma:=True
Range("A1:HS1").Copy
Windows("Exports.xls").Activate
Sheets("2700 Cash Files").Select
Range("B2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
Windows(MyFile).Close
Range("A1").Select