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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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,223,918
Messages
6,175,365
Members
452,638
Latest member
Oluwabukunmi

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