How to pause a macro to insert text?

I am trying to create a macro in Word 2010 that will pause to let me insert a zip code.  This is the code I have so far, but I can't figure out how to get it to pause so I can insert the actual zip code.  How do I insert the necessary pause command?  "Dummies" answer preferred!

 

Sub ZipCode()
'
' ZipCode Macro
'
'
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
        "BARCODE  \u 32247-2049 ", PreserveFormatting:=True
End Sub

 

 

Answer
Answer

Sub ZipCode()
'
' ZipCode Macro
'
'

    Dim Zip As String

    Zip = InputBox("Enter ZIP code")

    If Len(Trim(Zip)) = 0 Then Exit Sub

    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
        "BARCODE  \u " & Zip, PreserveFormatting:=True
End Sub


It would be a good idea to add some code that checks to be sure the value of the variable named Zip is in the correct format (either five digits or five-hyphen-four digits, no other characters). The Barcode field itself will do that, displaying the message "Zip code not valid!", but then you'd have to edit or delete the field that was already in the document and re-enter it.

_____________________________
https://jay-freedman.info

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated June 10, 2023 Views 1,224 Applies to: