
08-22-2006, 10:35 AM
|
|
|
|
Re: Run macro from command line
Alan,
Here's some basic code to see if this is what you mean.
You need to:
1 - Open Excel with a new workbook.
2 - Press Alt + F11
3 - You will looking at the VBA IDE. You should see a window with a tree
structure something like "VBAProject (Book1.xls)" with "Sheet1 (Sheet1)" etc
underneath and "ThisWorkbook" at the bottom
4 - Double this last entry, to open its code pane.
5 - Paste in the code below
6 - Close the file and save somewhere suitable.
7 - Double click the file to run the code. Depending on your security
setting, you may be asked if you want to enable macro; click Yes.
8 - Select the text file when asked in the dialog. The Excel file will be
saved to the same folder as the text file with the same name.
NickHK
'--------- Code
Option Explicit
Private Sub Workbook_Open()
Dim RetVal As Variant
Dim WB As Workbook
RetVal = Application.GetOpenFilename("TextFiles (*.txt),*.txt", , "Select
the text file to process", , False)
If RetVal = False Then Exit Sub
Set WB = Workbooks.Open(RetVal)
RetVal = Left(RetVal, InStr(1, RetVal, ".") - 1)
With WB
.SaveAs RetVal & ".xls", xlNormal
.Close
End With
'Application.Quit
End Sub
'--------- End Code
"Alan Wilson" <Alan.Wilson.2cxsw2_1156242608.2604@excelforum-nospam.com> ¼¶¼g©ó¶l¥ó·s»D:Alan.Wilson.2cxsw2_1156242608.2604@excelforum-nospam.com...
>
> Nick
> I'm not familiar with VBA: is there anyone you could recommend who I
> could pay to write the necessary code & detail how to embed it?
> Thanks
> alanwilson42@compuserve.com
>
>
> --
> Alan Wilson
> ------------------------------------------------------------------------
> Alan Wilson's Profile:
> http://www.excelforum.com/member.php...o&userid=37858
> View this thread: http://www.excelforum.com/showthread...hreadid=574090
>
|