Changing format of data assigned to DocVariable

O

OssieMac

Is there any way of changing the format of the data in a DocVariable?

I have the following code emulates what I have in an Access project where I
copy some data from an Access form to DocVariables in a Word document. I want
to be able to apply formatting to it such as bold font but can't find the
right code to do so.

Dim strMyData as string

strMyData = "My test text"
ActiveDocument.Variables("TestFont") = strMyData
ActiveDocument.Fields.Update


Any help will be greatly appreciated.
 
D

Doug Robbins - Word MVP

Add a \* Charformat switch inside the closing } of the Docvariable field and
then apply the desired format to the D of Docvariable.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
O

OssieMac

Firstly, thanks a million for taking the time to reply. However, I am no
further ahead. Where should I see the bracket like }? Perhaps I am not
creating the DocVariable the correct way so I'll describe what I am doing and
perhaps you can point me in the right direction.

I select Menu item Insert->Field->DocVariable.
I then type a name like MyNewVariable in the New Name box and click OK.

On the word document where I want the DocVariable all I see is "Error! No
document variable supplied". However, the variable is there because the error
message gets replaced with the required data when I run my macro.

Hoping you can help me some more and thanks again for taking the time.

--
Regards,

OssieMac


Doug Robbins - Word MVP said:
Add a \* Charformat switch inside the closing } of the Docvariable field and
then apply the desired format to the D of Docvariable.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

Press Alt+F9 to toggle on the display of the field codes and you will see

{ DOCVARIABLE [variablenamethatyouassigned] }

If there is a \* mergeformat switch there, you can delete it, or change it
to \* charformat

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

OssieMac said:
Firstly, thanks a million for taking the time to reply. However, I am no
further ahead. Where should I see the bracket like }? Perhaps I am not
creating the DocVariable the correct way so I'll describe what I am doing
and
perhaps you can point me in the right direction.

I select Menu item Insert->Field->DocVariable.
I then type a name like MyNewVariable in the New Name box and click OK.

On the word document where I want the DocVariable all I see is "Error! No
document variable supplied". However, the variable is there because the
error
message gets replaced with the required data when I run my macro.

Hoping you can help me some more and thanks again for taking the time.
 
O

OssieMac

Thankyou Doug. I am very grateful for your help. I have now achieved what I
set out to do.

--
Regards,

OssieMac


Doug Robbins - Word MVP said:
Press Alt+F9 to toggle on the display of the field codes and you will see

{ DOCVARIABLE [variablenamethatyouassigned] }

If there is a \* mergeformat switch there, you can delete it, or change it
to \* charformat

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

OssieMac said:
Firstly, thanks a million for taking the time to reply. However, I am no
further ahead. Where should I see the bracket like }? Perhaps I am not
creating the DocVariable the correct way so I'll describe what I am doing
and
perhaps you can point me in the right direction.

I select Menu item Insert->Field->DocVariable.
I then type a name like MyNewVariable in the New Name box and click OK.

On the word document where I want the DocVariable all I see is "Error! No
document variable supplied". However, the variable is there because the
error
message gets replaced with the required data when I run my macro.

Hoping you can help me some more and thanks again for taking the time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top