Ayuda con inputbox

ColdGeorge

Active Member
Joined
Aug 21, 2012
Messages
412
Office Version
  1. 2016
Platform
  1. Windows
Hola a todos
Esta instrucción es útil para ir a cierta página de mi documento en Word, el problema es que si presiono el botón Aceptar o Cancelar sin haber introducido un valor me muestra un error en la segunda línea. Cualquier ayuda será bienvenida.

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

Gracias de antemano,
ColdGeorge
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi
having understood your issue via translate I hope reply in English ok

try this update to your code & see if helps

VBA Code:
 Dim pagina As Variant
    
    Do
        pagina = InputBox("Introduce el número de la página", "Buscador de páginas")
        'cancel pressed
        If StrPtr(pagina) = 0 Then Exit Sub
    Loop Until Val(pagina) > 0
    
    pagina = CLng(pagina)
    
    Selection.GoTo wdGoToPage, wdGoToAbsolute, pagina

adjust code as required

Dave
 
Upvote 0
Solution
Hi Dave
Thanks for your help
This is my final version of code:

Dim pagina As Variant

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

If StrPtr(pagina) = 0 Then Exit Sub
Loop Until Val(pagina) > 0

pagina = CLng(pagina)

Selection.GoTo wdGoToPage, wdGoToAbsolute, pagina 'your page number here

MsgBox ("Listo estás en la página ") & pagina

End Sub

Thanks again,
ColdGeorge
 
Upvote 0
welcome glad update does what you want & appreciate your feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,224,836
Messages
6,181,251
Members
453,027
Latest member
Lost_in_spreadsheets

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top