View Single Post
 
Old 12-02-2015, 11:27 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use a Document_Open macro like the following in the 'ThisDocument' module of either your document or its template:
Code:
Sub Document_Open()
Application.ScreenUpdating = False
Dim StrName As String, StrQty1 As String, StrQty2 As String, StrVal As String
StrName = InputBox("What is the name?")
StrQty1 = InputBox("How many apples are there?")
StrQty2 = InputBox("How many apples do you want?")
StrVal = InputBox("How much each are they?")
Call UpdateBookmark("Name", StrName)
Call UpdateBookmark("Qty1", StrQty1)
Call UpdateBookmark("Qty2", StrQty2)
Call UpdateBookmark("Price", StrVal)
Application.ScreenUpdating = True
End Sub

Sub UpdateBookmark(StrBkMk As String, StrTxt As String)
Dim BkMkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(StrBkMk) Then
    Set BkMkRng = .Bookmarks(StrBkMk).Range
    BkMkRng.Text = StrTxt
    .Bookmarks.Add StrBkMk, BkMkRng
  End If
End With
Set BkMkRng = Nothing
End Sub
The macro populates four bookmarks in the document: "Name", "Qty1", "Qty2" and "Price". You should add these to the text, at the appropriate locations, then save, close & re-open the document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote