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!

How do I make an input form in word

Status
Not open for further replies.

JanTore

Technical User
Jun 9, 2001
34
NO
I'm looking for a way to have a inputbox pop out when you open a new dokument template in word. And put the text written in the box on a specified cell in a word table.

thanks
 
Hi, JanTore,

Not knowing what you are really doing, here's a way to do what you asked. It is entered in the ThisDocument Object ThisDocumenk_Open event...
Code:
Private Sub Document_Open()
    txt = InputBox("Enter text")
    If txt = "" Then
        'what to do if no text is entered
        
    Else
        ActiveDocument.Tables(1).Columns(1).Cells(1).Range.Text = txt
    End If
End Sub
Hope this helps :) Skip,
metzgsk@voughtaircraft.com
 
Hi there

Here are 10 Steps to make an input box which will put a string onto a word docment
If you want to a user form you can, but for a single piece of text which you suggest you want, an input box would be easier for you.

1 Alt F11 will take you thru to the VBA editing window

2 On the top menu click Insert

3 copy the code below into your module

Function txttodoc() As String
Dim Message, Title, Default, MyValue
Message = "Enter a value between 1 and 3" ' Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "1" ' Set default.
' Display message, title, and default value.
txttodoc = InputBox(Message, Title, Default)

End Function

Sub autonew()
Dim s As String
s = txttodoc
ActiveDocument.Bookmarks("bkmktst").Select
Selection.TypeText (s)


End Sub

4 At the top right of your screen you will see the word icon
click this.
5 You are now back at your document with the vba section
minimised to the statux bar at the bottom of your screen.
6 You are now going to insert a bookmark

Place the cursor AnyWhere on your screen
Go to the Insert on the top Menu
Select bookmark
copy bkmktst
into the book mark name

7 Click Add

If your sheet is blank and you want to see where your bookmarks are go to Tools on the top menu
Select Options
Click the View Tab- under Show 2nd from top is Bookmarks

select this and close the box
You should now be able to see an 'I' bar - this is your bookmark

8 Alt F11 or Double click the minimised VBA Icon at the
bottom to take you back to the code window

9 Place your cursor in the sub Autonew and press F5 to run or F8 to step thru the code.

10
return to your document window as before with word icon at the top of your vba window


your number will be at your book mark



Happy coding

regards


Jo





 
Hei thanks
Now I get it....

I did some modifications:
**********
Private Sub Document_Open()
UserForm1.Show
End Sub

Private Sub CommandButton1_Click()
ActiveDocument.Tables(1).Columns(2).Cells(1).Range.Text = Txt1
ActiveDocument.Tables(1).Columns(2).Cells(2).Range.Text = Txt2
End Sub
***********
Thanks again [medal]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top