ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Commandline Arguments (https://www.excelbanter.com/excel-programming/272520-commandline-arguments.html)

Tim[_16_]

Commandline Arguments
 
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?

Dave Peterson[_3_]

Commandline Arguments
 
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.

Tim wrote:

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?


--

Dave Peterson


Tim[_16_]

Commandline Arguments
 
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
-----Original Message-----
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?
.



All times are GMT +1. The time now is 05:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com