LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Save As Macro

Roy,

I wasn't sure how you had your command line set up at the start so I
suggested the command line option. My personal preference would be to place
a shortcut to the script in my SendTo folder which would allow me to right
click a csv file from Windows Explorer, send it into the shortcut and have
the xls file created. You can also use drag and drop into the script or you
can invoke the script from within a batch file. If you've disabled the vbs
file association for security reasons, you might need a different command
line that would include either cscript.exe or wscript.exe to launch the vbs
file and then the argument.

Steve



"Roy" wrote in message
...
Thanks Steve,

I'll give your suggestion a shot and see which I am most comfortable with.

I appreciated everyone's responses and suggestions. You guys are great!

Roy


"Steve Yandl" wrote:

Here is a slightly different approach. I create a vbScript file named
CSVtoXL.vbs which I stored in C:\Scripts. The content of the vbs file is
between the dotted lines below. I feed the script a csv file named
"C:\Test\RawTable.csv with the command line

C:\Scripts\CSVtoXL.vbs "C:\Test\RawTable.csv"

The script opens the csv file in Excel, saves it as an xls file with the
same file name and path as the csv file except for the extension and then
closes Excel.

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Const xlWorkbookNormal = -4143

' Only run script if it has been fed
If WScript.Arguments.Count = 0 Then
WScript.Echo "Need a file as a command line argument"
WScript.Quit
End If

fileCSV = WScript.Arguments.Item(0)

Set fso = CreateObject("Scripting.FileSystemObject")

If Not fso.FileExists(fileCSV) Then
WScript.Quit
End If

If Not Lcase(fso.GetExtensionName(fileCSV)) = "csv" Then
WScript.Quit
End If

strFileXL = fso.GetParentFolderName(fileCSV) & "\" & _
fso.GetBaseName(fileCSV) & ".xls"

Set objExcel = CreateObject("Excel.Application")
objExcel.DisplayAlerts = False
objExcel.Workbooks.OpenText fileCSV
objExcel.Application.ActiveWorkbook.SaveAs strFileXL, xlWorkbookNormal
objExcel.Quit

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Steve Yandl



"Roy" wrote in message
...
I often load CSV files into Excel and then re-save them as Excel
Workbooks
(*.xls) format. The loading of the CSV file is handled by a
command-line
that invokes Excel and loads the CSV.

After the CSV is loaded into Excel it would be VERY nice if a macro
could
be
executed that would then save the CSV in XLS format, instead of doing
the
SAVE As manually.

Suggestions would be welcome.







 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to Insert Current Date into cell - Macro to "Save As" Guy[_2_] Excel Worksheet Functions 4 December 12th 08 08:20 PM
Macro to Save without the Save Message Ellen G Excel Discussion (Misc queries) 4 February 23rd 07 08:52 PM
ASP: Open Excel File with Macro, Allow Macro to run, and then save delgados129 Excel Programming 0 March 10th 05 09:35 PM
Save As macro tjgriffi Excel Programming 1 January 5th 04 12:14 AM
Prompted to save changes after macro save - why? Izar Arcturus Excel Programming 2 December 10th 03 09:27 PM


All times are GMT +1. The time now is 09:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"