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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA InputBox In MS Word 2010

Status
Not open for further replies.

Boots6

Technical User
Aug 12, 2011
91
US
I am trying to automate Subcontract paperwork for my company and I can't figure out how to make it so my InputBox answers go to certain locations throughout my document. For example, everytime we use a new subcontractor, we have to go through about 30 pages of documents to enter their company name into our template. I have an inputbox created that pops-up asking for Subcontractor Name. How do I define where this information goes on my document once the name is entered and I hit ok? Thanks!
 

When you assign a value (Subcontractor Name) from your InputBox to a variable, how and where you declare this variable?

Show some code, that would help....

Have fun.

---- Andy
 
Let me preface this, with I'm a novice. I've been trying to look this up for 2 weeks though and nothing. All I have for my code is this:

Sub InsertBox()
Subcontractor = InputBox("Enter Sub Name")
Address = InputBox("Street Address")
Address2 = InputBox("Enter City, State, Zip")

End Sub

To get the pop up boxes. I just don't know what you put inbetween to send the information to a location. I'm trying to read VBA for Dummies, but I don't have the time. Thanks,
 

What I have done (Word 2003, but it should be the same in 2010) is set the Bookmarks in my document where I want to put the text. Let's say you have 5 places where you want to place SubContr name:

Bookmarks named:
"SubContr1", "SubContr2", "SubContr3", "SubContr4", "SubContr5"

In code then you may:
Code:
Sub InsertBox()
Dim strSubName As String
Dim i As Integer

strSubName = InputBox("Enter the Name of the SubContractor", "Name")

With .Selection
    For i = 1 To 5
        .GoTo What:=wdGoToBookmark, Name:="SubContr" & i
        .TypeText Text:=strSubName
    Next i
End With
End Sub
(Code not tested)

Have fun.

---- Andy
 
Awesome! I'll try it. It looks like it makes sense - I just need to read the basics. This is so fun!! Thank you !!!
 

Give it a try, post back any "It works! It works!" or "Crashes every time" :)

Welcome to tek-tips.

Have fun.

---- Andy
 
I keep getting Invalid or Unqualified reference at:

With .Selection
 
I played around and got it!! It's this:

Sub Subcontracter()
'
' Subcontracter Macro
'Dim strSubName As String
Dim i As Integer

strSubName = InputBox("Subcontractor")

With Selection
For i = 1 To 3
.GoTo What:=wdGoToBookmark, Name:="SubContr" & i
.TypeText Text:=strSubName
Next i

End With
End Sub

I don't know I changed a period or something. Thanks again!
 



Your company process for this Subcontract paperwork seems a lot more complicated than it might otherwise be.

Is the paperwork identical for each subcontract, except for the contractor and maybe a few standard paragraphs, or specific word here and there?

If so you ought to explore the Mail Merge feature.

Mail Merge does not necessarily mean that it can only be used for address lists and letters.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 

My fault, I gave you the line:
[tt]
With .Selection
[/tt]
with the period, but there should not be any periods. That's just a piece of my code from Visual Basic.
But you got it working, good for you :)

Have fun.

---- Andy
 
I will look into the mail merge feature, but this seems to work great except I can't put bookmarks in footers. Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top