#1
|
|||
|
|||
VBA user forms for auto filling word document
Hi, I am trying to write some simple code in VBA to use user forms to auto fill text in a Word document.
I have created bookmarks in the Word document and text boxes on the User form but when I click the OK command button nothing happens. this is the code I have written:- Private Sub cmdOK_Click() With ActiveDocument .Bookmarks("BorrowerName").Range.Text = txtBorrowerName.Value End With Any help would be gratefully received |
#2
|
||||
|
||||
I would recommend that you use the function FillBM from my web site (and repeated below) to fill the named bookmark (of which the spelling must be correct). The syntax here would be
FillBM "BorrowerName", txtBorrowerName.Text Code:
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 Code:
Private Sub cmdOK_Click() 'Hide the userform Hide 'e.g. Assign the values of the three text boxes to the three bookmarks 'Using the Function FillBM FillBM "bm1", TextBox1.Text FillBM "bm2", TextBox2.Text FillBM "bm3", TextBox3.Text 'Unload the form Unload Me End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
filling in forms character limit | benjii19 | Word | 1 | 12-29-2015 11:49 AM |
Problems with filling in forms | Gijs Verhoeff | Word | 0 | 09-24-2015 03:29 AM |
Automate filling in PDF Forms from Word? | dlowrey | Word | 5 | 09-23-2014 10:12 PM |
filling in forms | mepossem | Word | 3 | 05-25-2013 02:35 AM |
Filling out job application forms. | wordy | Word | 1 | 07-31-2012 12:16 PM |