DocVariable wont work

  • Follow


hi all

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

Please help thanks
0
Reply ent 3/14/2010 11:51:42 PM

Doug Robbins - Word MVP wrote:
> 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?
0
Reply ent 3/14/2010 11:25:44 PM


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

<ent@ent.ent> wrote in message news:ugAl4P9wKHA.5812@TK2MSFTNGP02.phx.gbl...
>
> hi all
>
> I try to insert a DocVariable into my document but when I do that form 
> Quickparts nothing happens
>
> Please help thanks 

0
Reply Doug 3/15/2010 12:28:57 AM

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

<ent@ent.ent> wrote in message news:ebby5i9wKHA.6140@TK2MSFTNGP05.phx.gbl...
> Doug Robbins - Word MVP wrote:
>> 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? 

0
Reply Doug 3/15/2010 2:13:33 AM

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


On Mon, 15 Mar 2010 12:13:33 +1000, "Doug Robbins - Word MVP"
<dkr@REMOVECAPSmvps.org> wrote:

>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"
0
Reply Gary 3/17/2010 1:20:43 AM

That problem has long since been fixed.

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"Gary Hillerson" <garyh@hillysun.net> wrote in message 
news:rcb0q593u1p97esmnfo3gsdlpm1vnte6c5@4ax.com...
> 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
>
>
> On Mon, 15 Mar 2010 12:13:33 +1000, "Doug Robbins - Word MVP"
> <dkr@REMOVECAPSmvps.org> wrote:
>
>>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" 


1
Reply Graham 3/17/2010 7:08:05 AM

When was it fixed?  Was it recently?  We are havign the same problem

Thanks.

"Graham Mayor" wrote:

> That problem has long since been fixed.
> 
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
> 
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> 
> 
> "Gary Hillerson" <garyh@hillysun.net> wrote in message 
> news:rcb0q593u1p97esmnfo3gsdlpm1vnte6c5@4ax.com...
> > 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
> >
> >
> > On Mon, 15 Mar 2010 12:13:33 +1000, "Doug Robbins - Word MVP"
> > <dkr@REMOVECAPSmvps.org> wrote:
> >
> >>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" 
> 
> 
> .
> 
0
Reply Utf 5/19/2010 1:08:03 PM

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"smile8691" <smile8691@discussions.microsoft.com> wrote in message 
news:B2FC45EC-3350-4FC0-827D-134C9D31561A@microsoft.com...
> When was it fixed?  Was it recently?  We are havign the same problem
>
> Thanks.
>
> "Graham Mayor" wrote:
>
>> That problem has long since been fixed.
>>
>> -- 
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor -  Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> "Gary Hillerson" <garyh@hillysun.net> wrote in message
>> news:rcb0q593u1p97esmnfo3gsdlpm1vnte6c5@4ax.com...
>> > 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
>> >
>> >
>> > On Mon, 15 Mar 2010 12:13:33 +1000, "Doug Robbins - Word MVP"
>> > <dkr@REMOVECAPSmvps.org> wrote:
>> >
>> >>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"
>>
>>
>> .
>> 


0
Reply Graham 5/19/2010 2:33:34 PM

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

"Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message 
news:OZ9TDB29KHA.4768@TK2MSFTNGP04.phx.gbl...
> 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
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> "smile8691" <smile8691@discussions.microsoft.com> wrote in message 
> news:B2FC45EC-3350-4FC0-827D-134C9D31561A@microsoft.com...
>> When was it fixed?  Was it recently?  We are havign the same problem
>>
>> Thanks.
>>
>> "Graham Mayor" wrote:
>>
>>> That problem has long since been fixed.
>>>
>>> -- 
>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>> Graham Mayor -  Word MVP
>>>
>>> My web site www.gmayor.com
>>> Word MVP web site http://word.mvps.org
>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>
>>>
>>> "Gary Hillerson" <garyh@hillysun.net> wrote in message
>>> news:rcb0q593u1p97esmnfo3gsdlpm1vnte6c5@4ax.com...
>>> > 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
>>> >
>>> >
>>> > On Mon, 15 Mar 2010 12:13:33 +1000, "Doug Robbins - Word MVP"
>>> > <dkr@REMOVECAPSmvps.org> wrote:
>>> >
>>> >>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"
>>>
>>>
>>> .
>>>
>
> 
0
Reply Doug 5/19/2010 10:32:45 PM

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

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> wrote in message 
news:3F56EEDD-C56D-44B0-941D-102808889087@microsoft.com...
> 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
>
> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message 
> news:OZ9TDB29KHA.4768@TK2MSFTNGP04.phx.gbl...
>> 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
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> "smile8691" <smile8691@discussions.microsoft.com> wrote in message 
>> news:B2FC45EC-3350-4FC0-827D-134C9D31561A@microsoft.com...
>>> When was it fixed?  Was it recently?  We are havign the same problem
>>>
>>> Thanks.
>>>
>>> "Graham Mayor" wrote:
>>>
>>>> That problem has long since been fixed.
>>>>
>>>> -- 
>>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>> Graham Mayor -  Word MVP
>>>>
>>>> My web site www.gmayor.com
>>>> Word MVP web site http://word.mvps.org
>>>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>>>
>>>>
>>>> "Gary Hillerson" <garyh@hillysun.net> wrote in message
>>>> news:rcb0q593u1p97esmnfo3gsdlpm1vnte6c5@4ax.com...
>>>> > 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
>>>> >
>>>> >
>>>> > On Mon, 15 Mar 2010 12:13:33 +1000, "Doug Robbins - Word MVP"
>>>> > <dkr@REMOVECAPSmvps.org> wrote:
>>>> >
>>>> >>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"
>>>>
>>>>
>>>> .
>>>>
>>
>> 


0
Reply Graham 5/20/2010 5:07:57 AM

9 Replies
1596 Views

(page loaded in 0.194 seconds)


Reply: