Hi
We have a system that creates a file with a non-standard extension - filename.0000. So the filename might be NRExport.4567. The next file to be exported would be NRExport.4568 and so on.
I open this file as a comma delimited file and perform some cleansing on the file using code. I then save the file as a text file. This all works fine until I want to close the file. I get a 'Subscript out of range' error on the line highlighted.
We have a system that creates a file with a non-standard extension - filename.0000. So the filename might be NRExport.4567. The next file to be exported would be NRExport.4568 and so on.
I open this file as a comma delimited file and perform some cleansing on the file using code. I then save the file as a text file. This all works fine until I want to close the file. I get a 'Subscript out of range' error on the line highlighted.
Code:
Sub SaveAs_ARIS_File()
Dim Original_Filename As String, New_Filename As String
Original_Filename = Worksheets("Sheet1").Range("A1")
Application.DisplayAlerts = False 'Turn off display alerts
Sheets(2).Select
Sheets(2).Move
ActiveWorkbook.SaveAs Filename:=Original_Filename & ".txt", FileFormat:=xlText, CreateBackup:=False
New_Filename = Original_Filename & ".txt"
'I get an error on this line - Subscript out of range
[COLOR=#ff0000] Workbooks(New_Filename).Close False[/COLOR]
Application.DisplayAlerts = True 'Turn on display alerts
End Sub
Last edited: