It's because the Inputbox returns "" when Cancel or escape is used.

Change the variable type and check for that return value

Sub Print_Pages()
   
    Dim StartPage As Long
    Dim Endpage As Variant
    Dim Page As Integer
    
    StartPage = 1
    
query:     Endpage = InputBox("From page 1 to...?")

    If Endpage = "" Then Exit Sub
'...
You should also check for non numeric values.
Or use the Application.Input box which would allow you to restrict input to numbers