Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move WorkSheet within Workbook using ActiveX in VBScript

Status
Not open for further replies.

spcheng7

Programmer
Feb 27, 2002
7
HK
Hi all,
I want to have a function that move the first workseet
to the last position within the same workbook, that is
for example, i have [ 1 2 3 4 5 ] worksheets in a workbook
A. Then I want to have a new order e.g. [ 2 3 4 5 1].

I have visited msdn and found that I should use a Move
method of WorkSheet object. But this object has two
optional parameters , "Before" and "After". Only either one
of them can be specified when I call this method.

Now, my question is what is the correct syntax in
VBScript since VBscript does not support optional parameters
Can anyone give me an example ? Thank you very much.

Tony
 
Hello spcheng7,

In vbs, [before] or [after] uses its position and name its object worksheet. Suppose your workbook is d:\test.xls. Here is how sheet moves.
Code:
set oxl=createobject("Excel.Application")
oxl.visible=true
oxl.workbooks.open "d:\test.xls"
set owb=oxl.activeworkbook

'move the first to [after] the last
owb.sheets(1).move ,owb.sheets(owb.sheets.count)
'move the now second sheet to [before] the first
owb.sheets(2).move owb.sheets(1)

'do other things
'close, clean up etc here omitted.
regards - tsuji
 
You have saved me , tsuji
I have solved my problem. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top