Prev: Protect code only
Next: Office 2007+ .doxc format
From: ent on 14 Mar 2010 19:51 hi all I try to insert a DocVariable into my document but when I do that form Quickparts nothing happens Please help thanks
From: Doug Robbins - Word MVP on 14 Mar 2010 20:28 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(a)ent.ent> wrote in message news:ugAl4P9wKHA.5812(a)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
From: ent on 14 Mar 2010 19:25 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?
From: Doug Robbins - Word MVP on 14 Mar 2010 22:13 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(a)ent.ent> wrote in message news:ebby5i9wKHA.6140(a)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?
From: Gary Hillerson on 16 Mar 2010 21:20
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(a)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" |