Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-01-2015, 08:41 AM
ryanch69 ryanch69 is offline VBA Macro for word with Inputbox Windows 10 VBA Macro for word with Inputbox Office 2010 64bit
Novice
VBA Macro for word with Inputbox
 
Join Date: Dec 2015
Posts: 2
ryanch69 is on a distinguished road
Default VBA Macro for word with Inputbox

Hi,

I have a standard Word template that I want to be prompted for information and once the information has been entered into the inputbox, i want it to appear in a location of my choice. Example

Dear XX,



You have 2x apples and if you would like 3x apples it will cost you £XX but we have a special deal on which means that you will only pay £XX.

I want to receive a prompt for "Name" and once entered I would like the "XX" to be replaced. The same thing for "2X" and "3X" and cost "£XX" etc. but with all separate prompts.

Thanks for your help in advance.
Reply With Quote
  #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: 21,963
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
  #3  
Old 12-03-2015, 07:45 AM
ryanch69 ryanch69 is offline VBA Macro for word with Inputbox Windows 10 VBA Macro for word with Inputbox Office 2010 64bit
Novice
VBA Macro for word with Inputbox
 
Join Date: Dec 2015
Posts: 2
ryanch69 is on a distinguished road
Thumbs up Solved

Thanks, that works great!!
Reply With Quote
Reply

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 02:03 PM.


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