#1
|
|||
|
|||
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. |
#2
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Solved
Thanks, that works great!!
|
Tags |
inputbox, macro, prompt |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |