(1) Using parameters instead of global variables is a good thing
(2) Avoiding to answer a question about parameter passing by proposing
to use globals is not a good thing
(3) In VBScript Parameters are passed by reference (default); this can
be changed by using "ByVal" in the function/sub definition or by
putting a parameter in "pass me per value" parentheses
Dim one : one = "one"
Dim two : two = "two"
WScript.Echo 0, one, two
toGerman one, (two)
WScript.Echo 1, one, two
toGerman one, two
WScript.Echo 2, one, two
Dim reOne : Set reOne = New RegExp
Dim reTwo : Set reTwo = New RegExp
WScript.Echo 3, CStr( reOne Is reTwo )
isSameObj 4, reOne, reOne
isSameObj 5, reOne, (reOne)
Sub toGerman( ByRef frs, ByRef sec ) ' ByRef is default
frs = "eins"
sec = "zwei"
Sub isSameObj( nCnt, o1, o2 ) ' ByRef is default
WScript.Echo nCnt, CStr( o1 Is o2 )
=== passParams: passing params (value/reference)
0 one two
1 eins two
2 eins zwei
=== passParams: 0 done (00:00:00) ===============
From output line 1 you can see that the () in "toGerman one, (two)"
send a copy of variable two to the sub. Changing this copy doesn't
affect the variable. Called without the () in "toGerman one, two" the
sub can do its work properly.
(4) While function calls need parameter list parentheses - e.g.
"Server.CreateObject("Excel.Application")", sub calls *don't*.
So you sub calls like "Create_WorkSheet_Header(objWorkSheet)" are
bad/misleading VBScript, because what looks like parameter list ()
are in fact "pass me per value" brackets. So write
or (if you like () and Call)
Call Create_WorkSheet_Header( objWorkSheet )
(4) Objects are references, so passing them by value (accidentialy)
will still allow access to same underlying object the reference
points to. See output line 5 as evidence: "isSameObj 5, reOne, (reOne)"
passes a reference and a copy of that reference, both point to the
(5) I don't know if I understand your
"this objExcel will have a new worksheet with new headers"
correctly. You use
Set objExcel = Server.*CreateObject*("Excel.Application")
That will start a *new* instance of Excel. Furthermore you
ask Excel to create a new workbook:
Set objWorkBook = objExcel.WorkBooks.Add
Of course it will have new sheets with new headers (if you write
them in Sub Create_WorkSheet_Header.
Perhaps you meant to use GetObject and/or .Workbooks.Open to
access an existing sheet?
(6) To sum up: I don't think that your problem is caused by parameter