MS Office Forum / Word / Programming / January 2005
Adding Autotext
|
|
Thread rating:  |
Greg Maxey - 22 Jan 2005 05:59 GMT Hello,
I am playing around with an addin for Word. I have saved the addin as a .dot file. When the addin runs creates an AutoText entry:
ActiveDocument.AttachedTemplate.AutoTextEntries.Add Name:="seqDate", Range:=Selection.Range
I need for the entry to be stored in the addin .dot template instead of the Normal template which is what occurs now.
I tried TemplateNameTemplate.AutoTextEntries.Add Name:="seqDate", Range:=Selection.Range And TemplateName.AutoTextEntries.Add Name:="seqDate", Range:=Selection.Range
where template name is the name of my template but I got and object error.
So I have a template that is function as an Addin. When the addin macro runs it creates an AutoText entry. I need the entry to be stored in the addin template and not the normal template. Thanks.
 Signature Greg Maxey/Word MVP A Peer in Peer to Peer Support
Greg Maxey - 22 Jan 2005 07:04 GMT OK,
I have learned that:
Templates(?).AutoTextEntries.Add Name .....
will work if I know the index number.
I cobbled together the following to figure out the index number of the template as the number can change if other templates and addin are involved
i = 0 For Each oTmp In Templates i = i + 1 If oTmp.Name = "DateSequencer.dot" Then Exit For End If Next
Then I use: Templates(i).AutoTextEntries.Add .....
Why does this have to be so hard. Why can't I just use my template name like: DateSequencer.AutoTextEntries.Add.... ???
Thanks.
 Signature Greg Maxey/Word MVP A Peer in Peer to Peer Support
> Hello, > [quoted text clipped - 18 lines] > macro runs it creates an AutoText entry. I need the entry to be > stored in the addin template and not the normal template. Thanks. Helmut Weber - 22 Jan 2005 11:42 GMT Hi Greg,
instead of a number as index you may use the templates fullname. s = oTmp.fullname Templates(s).AutoTextEntries.Add "Test3", Selection.Range
Greetings from Bavaria, Germany
Helmut Weber, MVP "red.sys" & chr(64) & "t-online.de" Word XP, Win 98 http://word.mvps.org/
Greg Maxey - 22 Jan 2005 13:38 GMT Helmut,
Last night I tried Dim oTmp as Template
Set oTem = DateSequencer.Dot
and got a compile error.
The method Jonathan has posted works fine.
Thanks.
 Signature Greg Maxey/Word MVP A Peer in Peer to Peer Support
> Hi Greg, > [quoted text clipped - 8 lines] > Word XP, Win 98 > http://word.mvps.org/ Greg Maxey - 22 Jan 2005 13:47 GMT Helmut,
I spoke too soon. I thought the method that Jonathan provided "would" work before actually trying. Please elaborate if you will on how to set oTmp to the template fullname.
Here is the whole snipet: i = 0 For Each oTmp In Templates i = i + 1 If oTmp.Name = "DateSequencer.dot" Then Exit For End If Next
'Create the AutoText Entry For Each oFld In ActiveDocument.Fields If oFld.Type = wdFieldDocVariable And Mid(oFld.Code.Text, 15, 9) = "Quote Var" Then oFld.Select Templates(i).AutoTextEntries.Add Name:="seqDate", Range:=Selection.Range Selection.Collapse Direction:=wdCollapseEnd If Templates(i).Saved = False Then Templates(i).Save Exit For End If Next
 Signature Greg Maxey/Word MVP A Peer in Peer to Peer Support
> Helmut, > [quoted text clipped - 20 lines] >> Word XP, Win 98 >> http://word.mvps.org/ Helmut Weber - 22 Jan 2005 14:50 GMT Hi Greg,
> If oTmp.Name = "DateSequencer.dot" Then s = oTmp.fullname
> Exit For > End If >Next Templates(s).AutoTextEntries.Add Name:="seqDate", _ Range:=Selection.Range
Seems, I must be missing something. Just set, if the template's name = "DateSequencer.dot", the variable s, which is the fullname, to oTmp.fullname.
You have been in Moscow? Wow!
Greetings from Bavaria, Germany
Helmut Weber, MVP "red.sys" & chr(64) & "t-online.de" Word XP, Win 98 http://word.mvps.org/
Greg Maxey - 22 Jan 2005 15:06 GMT Helmut,
Got it. I was trying to do something that wouldn't make sense.
Moscow??
 Signature Greg Maxey/Word MVP A Peer in Peer to Peer Support
> Hi Greg, > [quoted text clipped - 19 lines] > Word XP, Win 98 > http://word.mvps.org/ Helmut Weber - 22 Jan 2005 21:48 GMT Hi Greg, sorry, there was a question from a Greg from Moscow, "moving caret to cursor". Was a good question, could have been from You.
Greetings from Bavaria, Germany
Helmut Weber, MVP "red.sys" & chr(64) & "t-online.de" Word XP, Win 98 http://word.mvps.org/
Jonathan West - 22 Jan 2005 11:25 GMT > Hello, > [quoted text clipped - 6 lines] > I need for the entry to be stored in the addin .dot template instead of > the Normal template which is what occurs now. For that, you use ThisDocument. ThisDocument refers to the template containing the code that is running.
ThisDocument.AutoTextEntries.Add Name:="seqDate", Range:=Selection.Range
 Signature Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup
Greg Maxey - 22 Jan 2005 13:51 GMT Jonathan,
I tried this and got a compile error on the .AutoTextEntries
Method or data member not found.
Am I doing something wrong? Here is the whole snipet of code (with your line stetted out for now):
i = 0 For Each oTmp In Templates i = i + 1 If oTmp.Name = "DateSequencer.dot" Then Exit For End If Next
'Create the AutoText Entry For Each oFld In ActiveDocument.Fields If oFld.Type = wdFieldDocVariable And Mid(oFld.Code.Text, 15, 9) = "Quote Var" Then oFld.Select 'ThisDocument.AutoTextEntries.Add Name:="seqDate", Range:=Selection.Range Templates(i).AutoTextEntries.Add Name:="seqDate", Range:=Selection.Range Selection.Collapse Direction:=wdCollapseEnd If Templates(i).Saved = False Then Templates(i).Save Exit For End If Next
 Signature Greg Maxey/Word MVP A Peer in Peer to Peer Support
>> Hello, >> [quoted text clipped - 12 lines] > ThisDocument. .Add Name:="seqDate", > Range:=Selection.Range Jonathan West - 22 Jan 2005 18:49 GMT Hi Greg
> Jonathan, > [quoted text clipped - 4 lines] > > Am I doing something wrong? No, I forgot to include a vital element. It should be this
ThisDocument.AttachedTemplate.AutoTextEntries.Add _ Name:="seqDate", Range:=Selection.Range
Since ThisDocument is already a template, it is attached to itself. But since AttachedTemplate is a Template object while ThisDocument is a Document object, it does have an AutoTextEntries collection.
Sometimes it's necessary to be convoluted...
 Signature Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup
Greg Maxey - 22 Jan 2005 21:11 GMT Jonathan,
Perfect. Thanks.
 Signature Greg Maxey/Word MVP A Peer in Peer to Peer Support
> Hi Greg > [quoted text clipped - 17 lines] > > Sometimes it's necessary to be convoluted...
|
|
|