Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 12-02-2015, 11:27 PM
macropod's Avatar
macropod macropod is offline VBA Macro for word with Inputbox Windows 7 64bit VBA Macro for word with Inputbox 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
 

Tags
inputbox, macro, prompt



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Macro for word with Inputbox Idiot Proof Entry with InputBox arpirnat Word VBA 1 04-27-2015 10:03 PM
Taking input from InputBox from user SeattleITguy Excel Programming 1 01-28-2015 09:05 AM
VBA Macro for word with Inputbox Macro Question: Need help making a macro to highlight the first word in every sentence LadyAna Word 1 12-06-2014 10:39 PM
VBA to Find and Format Text string defined using Inputbox within selection sistemalan Word VBA 7 10-03-2014 07:28 AM
Modify vba code to print based on name in the InputBox OTPM Project 0 05-25-2011 02:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft