Prev: Points returned by Information(wdHorizontalPosition...)
Next: VBA code to manipulate a .jpeg Exif tag used by Explorer to store
From: nostabo on 15 Jan 2009 11:46 I can't seem to find a good source for information on using docvariables (online would be preferable) without coming back here everytime I have a question. I'm using Word 2007 and even the Microsoft online help is very scant. There seems to be an abundance of help with Excel macro programming (which I have done alot of), but Word automation (especially 2007) is hard to find. I have a document that I'm trying to automate (a contract) and I would like the ability to update only one field at a time and use docvaribales that are arrays. Formatting the output is also a question as I would like to highlight the inserted data in red for easier proofing by the user and insert the array data as a numbered list. Thanks for your advice... Rick
From: Jay Freedman on 15 Jan 2009 12:30 I can't point you to any specific source of information. While it's true that the VBA documentation in Word 2007 isn't well indexed compared to previous versions, and there are still nowhere near enough examples, for this particular topic the basics are there (look up "Variable Object" and "Variable Object Members"). I'm afraid you're asking far more of document variables than they can deliver. Starting with the lowest level, the .Value property of a Variable object is a simple String data type. That means it cannot contain an array or any formatting information. You can fake these things, of course, by embedding characters in the string that your macro can look for and interpret as "end of array item", or "start of formatting" and "end of formatting". The formatting could be signified in the string by HTML tags or something like that; then the macro would have to run wildcard Replace operations to turn the tags into real formatting. The array items could be separated with pipe characters, and the macro can use the Split and Join functions to go between the string and an in-memory array in a Variant variable. Before you jump on this as a solution, though, note this remark in the help topic about the .Value property: "Setting the Value property to a string longer than 255 characters generates an error." Depending on what your data looks like, you could run out of room very quickly. Instead of packing an array into a single document variable, you might have to use a separate variable for each array member and set up some naming convention to save and retrieve them. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. nostabo wrote: > I can't seem to find a good source for information on using > docvariables (online would be preferable) without coming back here > everytime I have a question. I'm using Word 2007 and even the > Microsoft online help is very scant. There seems to be an abundance > of help with Excel macro programming (which I have done alot of), but > Word automation (especially 2007) is hard to find. > > I have a document that I'm trying to automate (a contract) and I > would like the ability to update only one field at a time and use > docvaribales that are arrays. Formatting the output is also a > question as I would like to highlight the inserted data in red for > easier proofing by the user and insert the array data as a numbered > list. > > Thanks for your advice... > > Rick
From: Greg Maxey on 15 Jan 2009 12:41 Perhaps you could use the \*CharFormat switch in the DocVariables fields to format your output. Sub Test() With ActiveDocument .Variables("Red").Value = "Red text" .Fields.Update End With End Sub { DocVariables "Red" \* CharFormat } then seleect the "D" in "DocVariables" and apply red color. Jay Freedman wrote: > I can't point you to any specific source of information. While it's > true that the VBA documentation in Word 2007 isn't well indexed > compared to previous versions, and there are still nowhere near > enough examples, for this particular topic the basics are there (look > up "Variable Object" and "Variable Object Members"). > > I'm afraid you're asking far more of document variables than they can > deliver. Starting with the lowest level, the .Value property of a > Variable object is a simple String data type. That means it cannot > contain an array or any formatting information. > > You can fake these things, of course, by embedding characters in the > string that your macro can look for and interpret as "end of array > item", or "start of formatting" and "end of formatting". The > formatting could be signified in the string by HTML tags or something > like that; then the macro would have to run wildcard Replace > operations to turn the tags into real formatting. The array items > could be separated with pipe characters, and the macro can use the > Split and Join functions to go between the string and an in-memory > array in a Variant variable. > Before you jump on this as a solution, though, note this remark in > the help topic about the .Value property: "Setting the Value property > to a string longer than 255 characters generates an error." Depending > on what your data looks like, you could run out of room very quickly. > Instead of packing an array into a single document variable, you > might have to use a separate variable for each array member and set > up some naming convention to save and retrieve them. > > > nostabo wrote: >> I can't seem to find a good source for information on using >> docvariables (online would be preferable) without coming back here >> everytime I have a question. I'm using Word 2007 and even the >> Microsoft online help is very scant. There seems to be an abundance >> of help with Excel macro programming (which I have done alot of), but >> Word automation (especially 2007) is hard to find. >> >> I have a document that I'm trying to automate (a contract) and I >> would like the ability to update only one field at a time and use >> docvaribales that are arrays. Formatting the output is also a >> question as I would like to highlight the inserted data in red for >> easier proofing by the user and insert the array data as a numbered >> list. >> >> Thanks for your advice... >> >> Rick -- Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org
From: nostabo on 15 Jan 2009 22:11
Thanks Jay and Greg, I guess I'll give up on a DocVariable array, but the tip on formatting the "D" in the DocVariable field code worked...as far as font fomatting goes. So I guess I'll just keep asking questions here and we'll all learn something... "Greg Maxey" wrote: > Perhaps you could use the \*CharFormat switch in the DocVariables fields to > format your output. > > Sub Test() > With ActiveDocument > .Variables("Red").Value = "Red text" > .Fields.Update > End With > End Sub > > { DocVariables "Red" \* CharFormat } then seleect the "D" in "DocVariables" > and apply red color. > > > > > Jay Freedman wrote: > > I can't point you to any specific source of information. While it's > > true that the VBA documentation in Word 2007 isn't well indexed > > compared to previous versions, and there are still nowhere near > > enough examples, for this particular topic the basics are there (look > > up "Variable Object" and "Variable Object Members"). > > > > I'm afraid you're asking far more of document variables than they can > > deliver. Starting with the lowest level, the .Value property of a > > Variable object is a simple String data type. That means it cannot > > contain an array or any formatting information. > > > > You can fake these things, of course, by embedding characters in the > > string that your macro can look for and interpret as "end of array > > item", or "start of formatting" and "end of formatting". The > > formatting could be signified in the string by HTML tags or something > > like that; then the macro would have to run wildcard Replace > > operations to turn the tags into real formatting. The array items > > could be separated with pipe characters, and the macro can use the > > Split and Join functions to go between the string and an in-memory > > array in a Variant variable. > > Before you jump on this as a solution, though, note this remark in > > the help topic about the .Value property: "Setting the Value property > > to a string longer than 255 characters generates an error." Depending > > on what your data looks like, you could run out of room very quickly. > > Instead of packing an array into a single document variable, you > > might have to use a separate variable for each array member and set > > up some naming convention to save and retrieve them. > > > > > > nostabo wrote: > >> I can't seem to find a good source for information on using > >> docvariables (online would be preferable) without coming back here > >> everytime I have a question. I'm using Word 2007 and even the > >> Microsoft online help is very scant. There seems to be an abundance > >> of help with Excel macro programming (which I have done alot of), but > >> Word automation (especially 2007) is hard to find. > >> > >> I have a document that I'm trying to automate (a contract) and I > >> would like the ability to update only one field at a time and use > >> docvaribales that are arrays. Formatting the output is also a > >> question as I would like to highlight the inserted data in red for > >> easier proofing by the user and insert the array data as a numbered > >> list. > >> > >> Thanks for your advice... > >> > >> Rick > > -- > Greg Maxey - Word MVP > > My web site http://gregmaxey.mvps.org > Word MVP web site http://word.mvps.org > > > > |