Stuck on Visual Basic


Posted by Ciaran on November 02, 2001 12:32 AM

hello everyone can u please help me? i want to import two text files to the same workbook but i only know the code to impoert the two txt files to two seperate workbooks.
How can i modify the code to save in Data.xls but specify the sheet as well????
Code here to open i t xt file and save in data.xls:

Workbooks.OpenText FileName:= _
"C:\Supplier1.TXT", Origin:= _
xlWindows, StartRow:=12, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), _
Array(2, 4), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2))

'Save txt File to Excel SS Data.xls ActiveWorkbook.SaveAs FileName:= _
"C:\Data.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False



Posted by Russ on November 02, 2001 7:54 AM

I'm new to this but I believe you should change the save function from the Activeworkbook to Workbooks("data.xls").Worksheets("Sheet1") for the first text file and Workbooks("data.xls").Worksheets("Sheet2") for the second file.