Worksheets.add in VBScript overwrites existing worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Background: Opening a tab delimited file, generated by netsh, with Excel to
format the data. Formatting includes creating new worksheets.

Here's the short code in vbscript
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set objExcel = WScript.CreateObject("Excel.Application")
'Opening existing Workbook
Set objExcelWorkbook = objExcel.Workbooks.Open(filename)
'Adding worksheet to opened, existing workbook
objExcel.Worksheets.Ad
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

What happens with the above code is the data in the existing worksheet gets
overwritten, but the name of the worksheet is retained.

Value add:
Any good reference on vbscriipt, Excel specific objects & methods would be
appreciated. VBA references tend toward VB and not VBScript, which means you
waste a lot of time trying to figure out what objects and methods are
available and how they should be formatted.

Thanks in advance.
 
I've narrowed it down to the fact that the output file is not
xlWorkbookNormal format. I can't seem to change that when I do a SaveAs to a
new name. I get a message that the object doesn't support that method, i.e.,
FileFormat:=.

Any help still appreciated.
 
How about

objExcelWorkbook.Worksheets.Add?

Does it demonstrate the same behavior?

HTH
Kostis Vezerides
 
It works... I know I tried that, too (I even have it commented out in my
code), but it didn't work before.

How frustrating.

Thank you for your solution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top