Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

empty document variables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jan Kucera - 11 May 2006 18:12 GMT
Hi, XML Word format, I set these variables:
   <w:docVars>
     <w:docVar w:name="myVar1" w:val="Kibo" />
     <w:docVar w:name="myVar2" w:val="Xibo" />
     <w:docVar w:name="myVar3" w:val="Jaffo" />   ;-)))) getting loving
these...
     <w:docVar w:name="myVar4" w:val="" />
     <w:docVar w:name="myVar5" w:val="" />
   </w:docVars>

In the document, I have fields that refers to these variables.
However, the variables with empty strings are not present in the document!
The field reports an error and ActiveDocument.Variables.Count returns 3.

How can I set the variables to empty string?

Thanks,
Jan
Jonathan West - 11 May 2006 19:46 GMT
> Hi, XML Word format, I set these variables:
>    <w:docVars>
[quoted text clipped - 11 lines]
>
> How can I set the variables to empty string?

You can't. It is a holdover from the days before VBA when the method of
deleting a variable was to set it to a blank string. The nearest you can get
is to set it to a single space, and manage your code so that a single space
is treated as an empty string.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org 

Jan Kucera - 11 May 2006 20:24 GMT
> You can't. It is a holdover from the days before VBA when the method of
> deleting a variable was to set it to a blank string. The nearest you can
> get is to set it to a single space, and manage your code so that a single
> space is treated as an empty string.

Well, nothing else remains so I will do like that. But why is the Word then
saving variables with empty strings......

Thanks for pointing that out before I get mad :), Jan.
Jean-Guy Marcil - 12 May 2006 02:05 GMT
Jan Kucera was telling us:
Jan Kucera nous racontait que :

>> You can't. It is a holdover from the days before VBA when the method
>> of deleting a variable was to set it to a blank string. The nearest
[quoted text clipped - 3 lines]
> Well, nothing else remains so I will do like that. But why is the
> Word then saving variables with empty strings......

A string containing a space is not an empty string... ;-)

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

Jonathan West - 12 May 2006 10:53 GMT
> Jan Kucera was telling us:
> Jan Kucera nous racontait que :
[quoted text clipped - 8 lines]
>
> A string containing a space is not an empty string... ;-)

I think the question Jan was asking is why, if when you set a Variable to an
empty string and it therefore disappears from the Variables collection in
VBA, does the tag of the Variable still appear with empty content when you
save the file as XML?

And I have no definite answer. I suspect it is a bug.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org 

Jan Kucera - 12 May 2006 11:26 GMT
> I think the question Jan was asking is why, if when you set a Variable to
> an empty string and it therefore disappears from the Variables collection
> in VBA, does the tag of the Variable still appear with empty content when
> you save the file as XML?
>
> And I have no definite answer. I suspect it is a bug.

Yes Jonathan, that was the question - thanks. ;-)
However you wrote a new information to me - when I set the variable to the
empty string, it will be deleted?
I was sooo near using Variables.Add("myVar", '") just to define it and set
later...

Jan
Jonathan West - 12 May 2006 11:56 GMT
>> I think the question Jan was asking is why, if when you set a Variable to
>> an empty string and it therefore disappears from the Variables collection
[quoted text clipped - 6 lines]
> However you wrote a new information to me - when I set the variable to the
> empty string, it will be deleted?

Yes. At least, it will disappear from the Variables collection in VBA. As
you have seen, the matching XML tag seems not to disappear.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org 

Jean-Guy Marcil - 12 May 2006 14:49 GMT
Jonathan West was telling us:
Jonathan West nous racontait que :

<snip>

>>> Well, nothing else remains so I will do like that. But why is the
>>> Word then saving variables with empty strings......
[quoted text clipped - 5 lines]
> Variables collection in VBA, does the tag of the Variable still
> appear with empty content when you save the file as XML?

Well done.
Your crystal ball is better than mine!

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.