Ask a Question

Add New Worksheet at the End

SOLVED
SudhakarVE
New Contributor

Add New Worksheet at the End

Hi,

 

I'm trying to add a new worksheet at the end of the workbook. The following add method adds the worksheet at the first sheet. VBA After:= with count is not working in test complete.

 

sWritePath="Z:\Expected Data Report Files\ComSnapShot\Sample.xlsx"

Set oXL = CreateObject("Excel.Application")

Set oVPRWB = oXL.Workbooks.Open(sMainpath)

Set oPCSExpWB= oXL.Workbooks.Open(sWritePath)

oPCSExpWB.Worksheets.Add

 

Appreciate any idea to add the new sheet at the end.

 

Regards,

Sudhakar

4 REPLIES 4
TanyaYatskovska
SmartBear Alumni (Retired)

Hi Sudhakar,

 

The following code works for me:

sub Test1
  sWritePath="e:\Book1.xlsx"
  Set oXL = CreateObject("Excel.Application")
 
  Set oPCSExpWB= oXL.Workbooks.Open(sWritePath)
  Call oPCSExpWB.Worksheets.Add (, oPCSExpWB.Sheets(oPCSExpWB.Sheets.Count))
  oPCSExpWB.Save
  oXL.Quit
end sub

 

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



Hi:

 

This code works. Appreciate it

 

Thanks,

Sudhakar

Thats pretty much identical to what it says on the Stack post I linked to ....

cancel
Showing results for 
Search instead for 
Did you mean: