Forum Discussion

SudhakarVE's avatar
SudhakarVE
New Contributor
9 years ago

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.   sWrit...
  • TanyaYatskovska's avatar
    TanyaYatskovska
    9 years ago

    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