Commandline Arguments

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

I want to open excel using a template and pass an
argument that can be used in a macro, e.g excel.exe /t
template.xlt arg1
Does anyone know if this is possible?
 
I don't think so. In fact, when I tried it, excel opened my test template
file--not a new workbook based on the template.

Maybe you could save the template as readonly (on the network??), so that it
can't be saved. Then put your parm into a text file and have the
auto_open/workbook_open retrieve the value from that file.
 
Thanks for your replies.
I have solved the problem by calling the following
VBScript:

' This script will run open excel
' and run a macro based on the contents in a named cell
Const XLPATH = "\\PCResources\Templates\Excel\"
Const TEMPLATE = 0
Const SHEET = 1
Const RANGE = 2
Const MACRO = 3
Const KEY = 4

Dim MAXKEY
Dim app
Dim wb

Set objArgs = WScript.Arguments

If objArgs.count < 5 then
MAXKEY = ""
Else
MAXKEY = objArgs(KEY)
End If

'msgbox "Template " & objArgs(TEMPLATE)
'msgbox "Sheet " & objArgs(SHEET)
'msgbox "Range " & objArgs(RANGE)
'msgbox "Key " & MAXKEY

' Launch Excel
set app = createobject("Excel.Application")

' Make it visible
app.Visible = true

set wb = app.workbooks.add( XLPATH & objArgs(TEMPLATE))
wb.Worksheets(objArgs(SHEET)).Range(objArgs(RANGE)).Value
= MAXKEY
app.run(objArgs(MACRO))

set wb = nothing
set app= nothing

' I hope this is useful
 
Back
Top