numberchomper
New Member
- Joined
- Aug 19, 2009
- Messages
- 13
I am receiving an error "Subscript out of range" when trying to copy a worksheet from one workbook to another. The workbooks are selected by the user. I then want to copy the worksheet from workbook #2 and place it at the end of the worksheet in workbook #1. Below is my code with the offending line in red. (Please note that there is more code following this line, but I did not think it would be relevant.) Can someone please help me find the problem?
Sub CopySheetTest()
ChDrive "L:\"
ChDir "L:\SharedData\Houston\FinRpt\Corp Acct\"
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose the current Trial Balance exported from SAP R3", _
FileFilter:="DAT Files *.dat (*.dat),")
If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "Error"
Else
Workbooks.OpenText Filename:=FileToOpen _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1)), _
TrailingMinusNumbers:=True
End If
Range("A1").Select
Sheets(1).Select
File1Sheet1 = Sheets(1).Name
ChDrive "L:\"
ChDir "L:\SharedData\Houston\FinRpt\Corp Acct\"
FileToOpen2 = Application.GetOpenFilename _
(Title:="Please choose the current Qtrly Income Stmt exported from SAP R3", _
FileFilter:="DAT Files *.dat (*.dat),")
If FileToOpen2 = False Then
MsgBox "No file specified.", vbExclamation, "Error"
Else
Workbooks.OpenText Filename:=FileToOpen2 _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)), TrailingMinusNumbers:=True
End If
Sheets(1).Select
File2Sheet1 = Sheets(1).Name
Application.CutCopyMode = False
ActiveSheet(File2Sheet1).Copy After:=Workbooks(FileToOpen).Sheets(File1Sheet1)
End Sub
Sub CopySheetTest()
ChDrive "L:\"
ChDir "L:\SharedData\Houston\FinRpt\Corp Acct\"
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose the current Trial Balance exported from SAP R3", _
FileFilter:="DAT Files *.dat (*.dat),")
If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "Error"
Else
Workbooks.OpenText Filename:=FileToOpen _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1)), _
TrailingMinusNumbers:=True
End If
Range("A1").Select
Sheets(1).Select
File1Sheet1 = Sheets(1).Name
ChDrive "L:\"
ChDir "L:\SharedData\Houston\FinRpt\Corp Acct\"
FileToOpen2 = Application.GetOpenFilename _
(Title:="Please choose the current Qtrly Income Stmt exported from SAP R3", _
FileFilter:="DAT Files *.dat (*.dat),")
If FileToOpen2 = False Then
MsgBox "No file specified.", vbExclamation, "Error"
Else
Workbooks.OpenText Filename:=FileToOpen2 _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)), TrailingMinusNumbers:=True
End If
Sheets(1).Select
File2Sheet1 = Sheets(1).Name
Application.CutCopyMode = False
ActiveSheet(File2Sheet1).Copy After:=Workbooks(FileToOpen).Sheets(File1Sheet1)
End Sub