Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word pause for user input 1

Status
Not open for further replies.

gallas

Technical User
Joined
Feb 5, 2002
Messages
55
Location
GB
I'm looking for VBA code to do the following simple task in Word. This is basically a fax form filler.

In a document - Find a character (eg DOS pipe) delete it and pause for user input, re-start running code when return key is pressed. Of course you could search for a bookmark wait for user input and then re-start when return key is pressed.

Any ideas?
 
Hi,
You could use a simple InputBox in your code as follows...
Code:
    x = InputBox("Enter FAX stuff")
Hope this helps :-) Skip,
metzgsk@voughtaircraft.com
 
Thanks Skip, code works fine. I'm an absolute beginner at VBA so below is my code which works okay s-)(is it okay?). We will have about 6 prompts, Is it very complicated to get all the inputs from one input box dialogue?

' Test user input

Selection.GoTo What:=wdGoToBookmark, Name:="RecipientName"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

RecipName = InputBox("Enter Recipient Name")
Selection.TypeText Text:=RecipName

Selection.GoTo What:=wdGoToBookmark, Name:="CompanyName"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

CoName = InputBox("Enter Company Name")
Selection.TypeText Text:=CoName
 
Here's some code in a for...next loop to do a portion of what you may be looking for. Just add the cases for the remaining 4. I used With Selection...End With. If this does not work, then remove those 2 statements and add Selection before each . statement as you had them...
Code:
Sub GetImputs()
    Dim sName As String, sText As String
    With Selection
        For i = 1 To 6
            Select Case i
                Case 1
                    sName = "RecipientName"
                Case 2
                    sName = "CompanyName"
            End Select
            .GoTo What:=wdGoToBookmark, Name:=sName
            .Find.ClearFormatting
            .Find.Replacement.ClearFormatting
            sText = InputBox("Enter " & sName)
            Select Case i
                Case 1
                    RecipName = sText
                    .TypeText Text:=RecipName
                Case 2
                    CoName = sText
                    .TypeText Text:=CoName
            End Select
        Next
    End With
End Sub
Hope this helps :-) Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top