#1
|
|||
|
|||
Text Form Field & REF Field
Hi all,
I'm facing difficulties for populating data from excel to word's text form field. I've been using bookmarks in word in order to populate data from excel. However, due to the content that some data need to repeat in a document, I tried using Text Form Field and REF Field. The problem came in when once I populated data to word, the text form field placeholder disappear which causes REF Field unable to track the data that was referred to, hence, the "Error! Reference source not found." Is there anyway to retain the Text Field Form Placeholder after data is populated to word? So that I can generate duplicate data. My excel and document as attached for your reference. Appreciate for your help in advance! |
#2
|
||||
|
||||
Hi
is this question not intended for the MSWord forum?
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post |
#3
|
|||
|
|||
Should be at the right forum. Because I was asking for Excel VBA to solve my Text Form Field in Word. If there's solution for Word, it would be great.
|
#4
|
||||
|
||||
Form fields only work in documents with 'filling in forms' protection applied. Unless your VBA code was changing the formfield's default property, anything you do to update the formfield would erase its contents. As it is, the error you're getting suggests that you're not writing to the formfield but are instead overwriting it and, hence, deleting its bookmark.
Instead of writing to formfields, you could just write the data to a bookmark (not just insert it at a bookmarked location), and cross-reference that bookmark. For code to update Word bookmarks correctly for that, see: https://www.msofficeforums.com/word-...html#post67058
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Hi Macropod, thanks for replying.
I tried adding your code into my existing code, like this : Code:
Private Sub CommandButton1_Click() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Data Entry (B)") Dim objWord As Object Set objWord = CreateObject("Word.Application") Dim BkMkRng As Range objWord.Visible = True objWord.Documents.Open "C:\Users\" & Environ("username") & "\Desktop\xxx\xxxN" objWord.ActiveDocument.Unprotect Password:="xxx" With objWord.ActiveDocument .FormFields("pr1").Range.Text = ws.Range("C28").Value If .Bookmarks.Exists(StrBkMk) Then Set BkMkRng = .Bookmarks(StrBkMk).Range BkMkRng.Text = StrTxt .Bookmarks.Add StrBkMk, BkMkRng End If .Fields.Update objWord.ActiveDocument.Protect Password:="xxx", NoReset:=False, Type:=wdAllowOnlyFormFields End With Set objWord = Nothing End Sub |
#6
|
||||
|
||||
As I already said, there is no point using a formfield. what you should be using is a bookmark - which you update.
Furthermore, your code populates neither StrBkMk, BkMkRng, nor StrTxt and never defines either StrBkMk or StrTxt - even the definition of BkMkRng (as Range) is wrong in an automation context!
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to autofill a form field ONLY if the form field is blank upon entry | Pindar | Word VBA | 2 | 01-12-2017 05:03 PM |
Insert text form field help | sj80 | Word | 1 | 01-26-2016 10:50 PM |
Text form field in table | tmarsh | Word Tables | 1 | 02-23-2015 07:43 AM |
Form field selection allows entry into form text box | David C | Word | 1 | 10-24-2012 04:53 AM |
Form Fields - Create blank form text field with if statement? | LAssist2011 | Word | 5 | 12-14-2011 03:02 PM |