Triggering an update of AUTOTEXT programatically?

D

darrel

I'm working on a mini-document management system that is going to handle a
bunch of word files for us. I'm going to be naming the word files from my
..net application. The word files, themselves, are going to have a footer and
one of the things they'd like in the footer is the filename.

Now, the catch...I can easily change the filename via .net. However, I can't
figure out if there is a way to force Word to update the AutoText whenever
the filename is changed. Is anyone aware of a way to do this from .net?

I'm also not sure if this is the best newsgroup to post this in...if there
is a more applicable group, please point me in that direction...thanks!

-Darrel
 
S

Shauna Kelly

Hi Darrel

I assume you are using a { FILENAME \p } field? And it's in the footer and
you want to update it?

Assuming that this is in the first page footer of the first section of the
document, then the VBA code would be:
ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage).Range.Fields(1).Update

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
D

darrel

I assume you are using a { FILENAME \p } field? And it's in the footer and
you want to update it?

Assuming that this is in the first page footer of the first section of the
document, then the VBA code would be:
ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage).Range.Fields(1).
Update

Can I call this from outside the file itself? In otherwords, when I update
the filename via an asp.net web page, can I also trigger this update of the
contents of the word file as well?

Or is this a macro that has to exist in the Word file itself?

-Darrel
 
J

Jean-Guy Marcil

darrel was telling us:
darrel nous racontait que :
ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage).Range.Fields(1).
Update

Can I call this from outside the file itself? In otherwords, when I
update the filename via an asp.net web page, can I also trigger this
update of the contents of the word file as well?

Or is this a macro that has to exist in the Word file itself?

You cannot change the file content without opening it first.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
D

darrel

You cannot change the file content without opening it first.

Damn.

Well, let me rephrase. Is there any way in MS Word to get a file to update
auto-text upon open? Right now, by default, auto-text only updates when you
force it to. WHich, at least to me, seems to be rather pointless.

-Darrel
 
G

Greg

Darrel,

You can update AutoText or any other field on open with code in an
AutoOpen macro:

Sub AutoOpen()
Dim pRange As Word.Range
For Each pRange In ActiveDocument.StoryRanges
Do
pRange.Fields.Update
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
End Sub

The above updates all fields.
 
C

Charles Kenyon

If it is the filename and path AutoText (actually a field) you may want to
review http://gregmaxey.mvps.org/File_Name_And_Path.htm.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
Top