Forum Discussion
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
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 IfThe MsgBox "You cancelled the process" command is optional and can be omitted if you do not want it to appear.
2 Replies
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 IfThe MsgBox "You cancelled the process" command is optional and can be omitted if you do not want it to appear.
- Jorge5445Copper ContributorHi Doug
Thanks for your help, it works like a charm.
ColdGeorge