How to move worksheet from vbscript

R

Robert Stober

Hi,

I want to move the last worksheet to be the first, but I don't the syntax
becuase the method usually requires a named argument (Before:=location):

' create an Excel object
set xlApp = CreateObject("Excel.Application")
set xlWb = xlApp.ActiveWorkbook

' move the last worksheet to be the first...
xlWb.Sheets(xlWb.Sheets.Count).Move Before:=xlWb.Sheets(1)

This causes an error. I know that I can't use the Excel named argument
syntax, but then how DO I specify the location to move the sheet?

Many thanks in advance,

Robert Stober
 
J

Joe Fawcett

Robert Stober said:
Hi,

I want to move the last worksheet to be the first, but I don't the syntax
becuase the method usually requires a named argument (Before:=location):

' create an Excel object
set xlApp = CreateObject("Excel.Application")
set xlWb = xlApp.ActiveWorkbook

' move the last worksheet to be the first...
xlWb.Sheets(xlWb.Sheets.Count).Move Before:=xlWb.Sheets(1)

This causes an error. I know that I can't use the Excel named argument
syntax, but then how DO I specify the location to move the sheet?

Many thanks in advance,

Robert Stober
For the before method just use:
xlWb.Sheets(xlWb.Sheets.Count).Move xlWb.Sheets(1)

for after I think you need:
xlWb.Sheets(xlWb.Sheets.Count).Move , xlWb.Sheets(1)

For future just open Excel, alt+F11 then F2, choose Excel in top dropdown
box and search on move, you can see the syntax and if you have help
installed press F1 when on the relevant entry.

Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top