adding sheets in same workbook

cesarvb6

New Member
Joined
Mar 20, 2011
Messages
3
Hi: I try to write in excel 2 textfiles in 2 sheets but only write the last
i think i missing something but i dont know, thanks for yuor help

Dim
xl As Object
xl = CreateObject("Excel.Application")
xl.Visible =
False
xl.Workbooks.Add()

xl.Workbooks.OpenText(Filename:="C:\Documents and Settings\User\Desktop\429\sheet1" & ".txt", Origin:=Excel.XlPlatform.xlMSDOS, StartRow:=1, _
DataType:=Excel.XlTextParsingType.xlFixedWidth, TextQualifier:=Excel.XlTextQualifier.xlTextQualifierNone, _
ConsecutiveDelimiter:=
False, Tab:=False, Semicolon:=True, Comma:=False, Space:=False, Other:=False, _
FieldInfo:=
New Object() {New Object() {0, 2}, New Object() {9, 9}, _
New Object() {11, 1}, New Object() {12, 9}, New Object() {14, 1}, New Object() {46, 1}, _
New Object() {56, 9}, New Object() {58, 5}, New Object() {64, 9}, New Object() {66, 1}, _
New Object() {74, 9}, New Object() {76, 1}, New Object() {82, 9}, New Object() {84, 1}, _
New Object() {89, 9}, New Object() {91, 5}, New Object() {97, 9}, New Object() {99, 5}, _
New Object() {105, 9}, New Object() {107, 5}, New Object() {113, 9}, New Object() {115, 1}, _
New Object() {116, 9}})
xl.workSheets(
"Sheet" & 1).Select()
xl.workSheets(
"Sheet" & 1).name = "cesar"

'xl.Workbooks.Add()
xl.Workbooks.OpenText(Filename:="C:\Documents and Settings\User\Desktop\429\sheet2" & ".txt", Origin:=Excel.XlPlatform.xlMSDOS, StartRow:=1, _
DataType:=Excel.XlTextParsingType.xlFixedWidth, TextQualifier:=Excel.XlTextQualifier.xlTextQualifierNone, _
ConsecutiveDelimiter:=
False, Tab:=False, Semicolon:=True, Comma:=False, Space:=False, Other:=False, _
FieldInfo:=
New Object() {New Object() {0, 2}, New Object() {9, 9}, _
New Object() {11, 1}, New Object() {12, 9}, New Object() {14, 1}, New Object() {46, 1}, _
New Object() {56, 9}, New Object() {58, 5}, New Object() {64, 9}, New Object() {66, 1}, _
New Object() {74, 9}, New Object() {76, 1}, New Object() {82, 9}, New Object() {84, 1}, _
New Object() {89, 9}, New Object() {91, 5}, New Object() {97, 9}, New Object() {99, 5}, _
New Object() {105, 9}, New Object() {107, 5}, New Object() {113, 9}, New Object() {115, 1}, _
New Object() {116, 9}})
xl.workSheets(
"Sheet" & 2).Select()
xl.workSheets(
"Sheet" & 2).name = "martinez"
xl.Worksheets(1).SaveAs("C:\Documents and Settings\User\Desktop\filetemp\bo" & ".xls", Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange)

xl.Quit()
xl =
Nothing
End
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Perhaps

Code:
WorkSheets,Add After:=Worksheets(workskeets.count),count:=2
 
Upvote 0
Sorry, typos

Code:
Worksheets.Add After:=Worksheets(Worksheets.Count), Count:=2
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top