VBA Pages.Add multipage crashes Excel. RRS feed

  • Question

  • Help.

    I've tried mutiple variations of this code, from TechNet and other website experts and nothing works!!

    I have an Excel form,  that has a multipage on it.  I have a default set of pages as tabs, but want to allow the program to dynamically add pages and tabs based on input from the user.

    Now the following code has been tried called by a buttonClick and other methods.  I'm running Win 10 with Office 365, but nothing works.

    now In a seperate excel worksheet I've tried to add a multipage, and it's functioned ok, but this particular form is having all kinds of problems.  There is no Error code or Error Msg that I can give to you cause when it hits the Pages.Add statement, excel crashes HARD.  The only information is from the App Log in event viewer.

    Faulting application name: EXCEL.EXE, version 16.0.11929.20300, time stamp: 0x5d6eab24

    Faulting module name: ntdll.dll, version 10.0.17763.831, time stamp: 0x1f1a0210

    Exception code: 0xc0000028

    Fault offset: 0x00000000009eb78

    Faulting process id: 0x15c0

    Faulting application start time: 0x1d5a6f391b221bd

    Faulting application path: C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE

    Faulting module path: C:\Windows\SYSTEM32\ntdll.dll

    Report Id: 1a72523f-bbd7-459b-b559-78f99708adc7

    Faulting package full name:

    Faulting package-relative application ID:

    Event ID: 1000                           Task Category:  (100)


    Private Sub PageMod(SC_Name As String, index As Byte)

    Dim Pname As String, Pcaption As String
    Dim newp As MultiPage      ' I've tried as Page and as MSForms.Page

    On Error GoTo ErrorOccured

    ' These two lines end up with the values expected.

       Pname = "subc" & index
       Pcaption = left(Sheet16.Range(SC_Name).Value, 8)
       ' every time the program hits this line it crashes HARD!!!!, the On Error code does not run at all.   No visible message just closes EXCEL and the VBA project screen.  Only reference is in the Application event log

       ' I've tried without the parameters on the command line set newp = Me.ReviewForm.Pages.Add, etc.
       Set newp = Me.ReviewForm.Pages.Add("Pname", "Pcaption", (index + 1))
        ' this code never runs,
        MsgBox "An Error has Occured" & vbCrLf & "The error number is: " & _
          Err.Number & vbCrLf & Err.Description & vbCrLf & _
          "Please notify the administrator"
    End Sub

    Friday, November 29, 2019 9:16 PM