View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Newbie Scriptor Newbie Scriptor is offline
external usenet poster
 
Posts: 1
Default how to lmport a text file and save it as an excel file using vb s.

I am trying to import a text file and save it as a normal excel file in VB
Script. I first recorded a macro that has steps to open the text file parse
it into columns and save it into a excel 2003 file. However when I copy and
past the macro with changes necessary for the VB script , vb script either
fails in the save-as step or brings up an interactive diaglog box for saving.
What is the way todo with out bringing up the diaglog box. Below is my simple
code..

Dim oXcel
Set oxcel = CreateObject("excel.Application")
oxcel.workbooks.add
oxcel.workbooks.OpenText "MyFile.txt"
oxcel.Rows("1:1").Select
oxcel.Selection.Font.Bold = True
oxcel.Columns("A:J").Select
oxcel.Range("J1").Activate
oxcel.Selection.Columns.AutoFit

ON Error Resume Next
oxcel.workbooks.SaveAs "MyFile.xls",4
if err.number < 0 then
wscript.echo "SaveAs error:",err.description
end if

On Error goto 0
oxcel.quit
Set oxcel = Nothing

=====
thanks
Newbie Scriptor