![]() |
#1
|
|||
|
|||
![]()
Hello,
I am looking to create a fairly simple form. I would like the document to have 2 or 3 prepopulated forms. It should be preceded with the variables that need to be replaced within the forms, and then a check list at the bottom where the user can select the form they would like to be generated: Name Address _ Form 1 _ Form 2 _ Form 3 Once the name and address are filled in, the user selects the form they want and it the form should pop up with all the variables filled in. What functionalities of Word/VBA am I looking at using here to accomplish this? Thank you for your help! |
#2
|
||||
|
||||
![]()
So not a simple form at all? The common sense approach would be simply to have three forms, but who is going to be completing this form?
if you want the form contents all to be contained in a single form then you will need to create a template to contain the macro code and the three alternative 'forms' as autotext entries. You would then need a bookmark in the body of the template to take the autotext content. Create a userform to gather the data and the form choice and then a pair of macros to apply the required autotext entry to the bookmark and to write the data collected to bookmarks contained in the inserted autotext entries. e.g. as follows. This only has one data bookmark. You can have as many as you need and call the function for each. If the bookmark doesn't exist the macro to fill that bookmark doesn't do anything. Code:
Sub AutoTextToBM(strbmName As String, oTemplate As Template, strAutotext As String) 'strBMName is the name of the bookmark to fill 'oTemplate is the template with the autotext - probably ActiveDocument.AttachedTemplate 'strAutotext is the name of the autotext entry Dim orng As Range With ActiveDocument Set orng = .Bookmarks(strbmName).Range Set orng = oTemplate.AutoTextEntries(strAutotext).Insert _ (Where:=orng, RichText:=True) .Bookmarks.Add Name:=strbmName, Range:=orng End With lbl_Exit: Exit Sub End Sub Public Sub FillBM(strbmName As String, strValue As String) 'Graham Mayor - http://www.gmayor.com Dim orng As Range With ActiveDocument On Error GoTo lbl_Exit Set orng = .Bookmarks(strbmName).Range orng.Text = strValue orng.Bookmarks.Add strbmName End With lbl_Exit: Set orng = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
Thank you for the reply. This helps quite a bit, a bit more complex than what I expected the solution to be, but nonetheless, doable, thank you very much.
|
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Outlook 2013 Forms (how to questions)- Quick opening of a form file & Linking form's data to Excel | gamin2407 | Outlook | 0 | 01-21-2017 10:14 PM |
To Box is Prepopulated | Learn2010 | Outlook | 0 | 02-12-2016 08:20 AM |
![]() |
DLee-AB | Word | 2 | 02-08-2016 03:30 PM |
Creating Forms for users to complete | dalaurienzo | Word | 1 | 07-19-2010 04:12 PM |
creating forms on word 2007 | Incasa | Word | 2 | 04-28-2009 10:47 PM |