View Single Post
 
Old 02-23-2014, 05:53 PM
Ulodesk Ulodesk is offline Windows 7 64bit Office 2013
Word 2013 Expert Cert
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Setting up a form to bring in text for other documents

I am having problems with a macro from Greg Maxey's site. I can't get the text to come into the document. The requirement is simple. I'm creating a document which will have a number of items listed, each with a check box. The idea is that when a checkbox is checked, the exit macro grabs text from a corresponding document and inserts it at a book mark on a subsequent page.
I created two word docs, Text1 and Text2 on the desktop. Each has just a paragraph or two in it. I copied Greg's macro into my normal template,and replaced his document location and names with mine. I created a trial check box, created a bookmark on the next page, and restricted editing to filling out forms, according, I thought, to his directions on the site page I have now spent 30 minutes looking for and cannot find; it's not in my browser history and no search turns it up.

Anyway, the text is not being brought in.
I am attaching the trial document and the code is below. I have with heavy irony, inserted the name Genius instead of the real user name in the path. I hope someone can quickly spot my error.

Code:
Sub OnExitCB1()
Dim rText As Range
Dim sTrue As String
Dim sFalse As String
Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
sTrue = """C:\\Users\\Genius\\Desktop\\Text1.docx"""
sFalse = """C:\\Users\\Genius\\Desktop\\Text2.docx"""
Set rText = ActiveDocument.Bookmarks("Check1Result").Range
If oFld("Check1").CheckBox.Value = True Then
rText , wdFieldIncludeText, sTrue, False
rText.MoveEnd wdCharacter, 1
Else
rText.Fields.Add rText, wdFieldIncludeText, sFalse, False
rText.MoveEnd wdCharacter, 1
End If
With ActiveDocument
.Bookmarks.Add "Check1Result", rText
.Fields.Update
End With
End Sub
Attached Files
File Type: docx Form page.docx (17.0 KB, 11 views)
Reply With Quote