![]() |
#1
|
|||
|
|||
![]()
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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
mortcr | Word VBA | 1 | 10-22-2013 02:02 PM |
![]() |
DBrooks | Word | 1 | 02-16-2013 01:32 PM |
![]() |
David C | Word | 1 | 10-24-2012 04:53 AM |
![]() |
kellyjb27 | Word | 1 | 05-26-2012 11:08 AM |
![]() |
LAssist2011 | Word | 5 | 12-14-2011 03:02 PM |