Change value of Word MailMerge field using VBA -


i have document mailmerge fields, not want use whole datasource->mailmerge idea. instead presenting userform on autonew() , asking user type data fields.

the reason because document "merged" 1 row of data waste of time asking user whole data source thing 1 row.

i have working solution using docvariables i'm sure people correct way it, client likes idea of "seeing" mailmerge variable (such <<1>>) in source document. know can use alt-f9 display codes see docvariables, insist on wanting use mergefields.

using docvariables using following. works know have right idea , rest of code works fine.

activedocument.variables("varsurame").value = .txtsurname 

however, cannot workout how same thing merge fields. want below (but there no "value" property set).

activedocument.mailmerge.fields("surname").value = .txtsurname 

the .text property readonly cannot use that.

the following renders "bookmark not defined" errors.

activedocument.mailmerge.fields("surname").code.text = .txtsurname 

any ideas on how can programmatically change value of mail merge field without using datasource.

something like:

dim f word.field  each f in activedocument.fields    if f.type = wdfieldmergefield      ' either need extract name of field f.code here     ' (roughly speaking, should expect find     ' mergefield<white space><optional double quote>fieldname<optional double quote><white space><possible switches>     ' or iterate through list of field names , use instr each name     '      f.result.text = "the text want"   end if next ' f 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -