Subscript out of range in VB Script

Vijayaprasath 0 Reputation points
2023-03-02T06:04:10.3966667+00:00

Subscript out of range in VB Script,

We are currently using VB Script inside the SAS Code, it works fine with the local sas server,

But while running the code in the SAS GRID server, VB script throws an error stating like "Subscript out of range"

"With oExcel
.Sheets(1).ListObjects.Add 1, .Sheets(1).Range(sRange), , , "Tableau1"
.Sheets(1).ListObjects("Tableau1").TableStyle = "TableStyleLight2"
   .Sheets.Add .Sheets(1)
   .Sheets(1).Range("B1").VerticalAlignment = -4160
   Set ZGPPict = .Sheets(1).Range("B2").Worksheet.Pictures.Insert(ZGPPicture)
   For iRowAdd = 1 To 6
       .Sheets(1).Rows("1").EntireRow.Insert
   Next"

This part of the code we getting an error.

Developer technologies | VB
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2023-03-02T20:17:49.3466667+00:00

    Try adjusting the first lines:

    With oExcel
        Dim t As ListObject
        Set t = .Sheets(1).ListObjects.Add(1, .Sheets(1).Range(sRange), , , , "TableStyleLight2")
        t.Name = "Tableau1"
        . . .
    

    Or:

    With oExcel
        Dim t As ListObject
        Set t = .Sheets(1).ListObjects.Add(1, .Sheets(1).Range(sRange))
        t.Name = "Tableau1"
        t.TableStyle = "TableStyleLight2"
        . . .
    

    If Dim t As ListObject does not work, then try Dim t.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.