Good morning people.
I am trying to import a text file into my existing spreadsheet tab. If I open a blank spreadsheet, and click File --> Open --> Filename it populated the Worksheet and changes Sheet1 to the filename (eg. Customers).
When I do the same thing in code, it creates a new spreadsheet with a Customers tab.
I want to have the imported information on the same tab and on the same spreadsheet without creating a new one each time.
I have the following code:
Sub Import()
'Dim filetoopen As Variant
ChDrive "O" 'Set Drive letter
ChDir ("O:\UA\OPSFIN\Premium Collections and Accounting\Outstanding Check Letters")
filetoopen = Application.GetOpenFilename("Text Files (*.txt), *.txt, Excel Files (*.xls), *.xls, All Files (*.*), *.*")
If filetoopen <> False And filetoopen <> "" Then
Workbooks.OpenText Filename:= _
filetoopen _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=True, OtherChar:="~", FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 3), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 3), Array(13, 9), Array(14, 9), Array(15 _
, 9), Array(16, 9), Array(17, 9), Array(18, 9), Array(19, 9), Array(20, 9), Array(21, 9), _
Array(22, 9), Array(23, 9), Array(24, 9), Array(25, 9), Array(26, 9), Array(27, 9), Array( _
28, 9)), TrailingMinusNumbers:=True
End Sub
Any suggestions?
Thank you,
Picard012
I am trying to import a text file into my existing spreadsheet tab. If I open a blank spreadsheet, and click File --> Open --> Filename it populated the Worksheet and changes Sheet1 to the filename (eg. Customers).
When I do the same thing in code, it creates a new spreadsheet with a Customers tab.
I want to have the imported information on the same tab and on the same spreadsheet without creating a new one each time.
I have the following code:
Sub Import()
'Dim filetoopen As Variant
ChDrive "O" 'Set Drive letter
ChDir ("O:\UA\OPSFIN\Premium Collections and Accounting\Outstanding Check Letters")
filetoopen = Application.GetOpenFilename("Text Files (*.txt), *.txt, Excel Files (*.xls), *.xls, All Files (*.*), *.*")
If filetoopen <> False And filetoopen <> "" Then
Workbooks.OpenText Filename:= _
filetoopen _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=True, OtherChar:="~", FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 3), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 3), Array(13, 9), Array(14, 9), Array(15 _
, 9), Array(16, 9), Array(17, 9), Array(18, 9), Array(19, 9), Array(20, 9), Array(21, 9), _
Array(22, 9), Array(23, 9), Array(24, 9), Array(25, 9), Array(26, 9), Array(27, 9), Array( _
28, 9)), TrailingMinusNumbers:=True
End Sub
Any suggestions?
Thank you,
Picard012