DocVariable wont work

E

ent

Doug said:
You must use code (vba) to assign a value to the variable and you may
need to update the field so that the value assigned to the variable is
displayed.

What am I doing wrong:

1: I created a macro associated to the CTRL-K keyboard sequence.

The macro is Macro11 and it reads like this:

Sub Macro11()
'
' Macro11 Macro
'
Dim varYELLOW As String
varYELLOW = "Tom"
ActiveDocument.Variables.Add Name:="docvarONE", Value:=varYELLOW
'
End Sub


2: I insert a DocVariable in my document, it reads, in the document:

<brace>DOCVARIABLE docvarONE \* MERGEFORMAT<brace>


3: I press CTRL-K

I get RUNTIME ERROR 5903 THE VARIABLE NAME ALREADY EXISTS.

the string "Tom" never appeared in my document and if i go Print Preview
I get: ERROR! NO DOCUMENT VARIABLE SUPPLIED where the docVariable field is.


What am I doing wrong?
 
E

ent

hi all

I try to insert a DocVariable into my document but when I do that form
Quickparts nothing happens

Please help thanks
 
D

Doug Robbins - Word MVP

You must use code (vba) to assign a value to the variable and you may need
to update the field so that the value assigned to the variable is displayed.

--
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, originally posted via msnews.microsoft.com
 
D

Doug Robbins - Word MVP

With document variables, you do not need to use .Add

Just use:

ActiveDocument.Variables("docvarONE").Value = "varYELLOW" (or just
varYELLOW if varYELLOW is declared somewhere else in your code and has
something assigned to it)

to add a variable docvarONE to the active document with the value of the
variable being varYELLOW

To change the value of the variable, just use

ActiveDocument.Variables("docvarONE").Value = "Something else"

--
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, originally posted via msnews.microsoft.com
 
G

Gary Hillerson

If you're trying to save a Word 2007 doc with variables in it, you may
run into a problem that Microsoft introduced last spring in a security
update -- document variables can get corrupted when you save in .docx
format.

The easy solution is to use document properties instead of variables.
They work pretty much the same way as variables, but seem to be more
reliable. Look at ActiveDocument.CustomDocumentProperties

Gary
 
G

Graham Mayor

That problem has long since been fixed.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

It was around August last year. I can't recall all the details, but the
problem came with a security update - KB969604 - which I understand was
later fixed. However uninstalling the above update and telling the update
installer not to put it back should fix it.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Doug Robbins - Word MVP

Hi Graham,

The only thing is that documents that were buggered by the problem, remain
buggered.

--
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, originally posted via msnews.microsoft.com
 
G

Graham Mayor

That's very true. It was a nasty bug :(

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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