Forum Discussion

Jorge5445's avatar
Jorge5445
Copper Contributor
Aug 02, 2023
Solved

I need help with this code

Hi all

I use this piece of code to go to any page of my word document

Dim pagina As Long
pagina = InputBox("Introduce el número de la página", "Buscador de páginas")

Selection.GoTo wdGoToPage, wdGoToAbsolute, pagina

My problem is when I press the Ok or the Cancel button of the inputbox with no value, the second line of code is highlited .

Thanks in advance for your assistance to prevent that error

ColdGeorge

  • Jorge5445 

    Use the following code

     

    Dim pagina As Long
    On Error GoTo ErrHndlr
    pagina = InputBox("Introduce el número de la página", "Buscador de páginas", pagina)
    Selection.GoTo wdGoToPage, wdGoToAbsolute, pagina
    ErrHndlr:
    If Err.Number = 13 Then
         MsgBox "You cancelled the process"
         Exit Sub
    End If

     

    The  MsgBox "You cancelled the process" command is optional and can be omitted if you do not want it to appear.

2 Replies

  • Jorge5445 

    Use the following code

     

    Dim pagina As Long
    On Error GoTo ErrHndlr
    pagina = InputBox("Introduce el número de la página", "Buscador de páginas", pagina)
    Selection.GoTo wdGoToPage, wdGoToAbsolute, pagina
    ErrHndlr:
    If Err.Number = 13 Then
         MsgBox "You cancelled the process"
         Exit Sub
    End If

     

    The  MsgBox "You cancelled the process" command is optional and can be omitted if you do not want it to appear.

    • Jorge5445's avatar
      Jorge5445
      Copper Contributor
      Hi Doug
      Thanks for your help, it works like a charm.
      ColdGeorge

Resources