Use of Macro in combination with auto text and comment field

D

DavidUK

Hi,
What I want to do is create a macro button so that I can automatically
insert a comment field with some auto text in it. It works fine if I do it
manually – I can insert a comment into the text and then select the comment
field and place auto text into this. However, when I try to do this procedure
using a macro I get Run time error 5941 “The requested member of the
collection does not exist†Any ideas? I am using Word 2007.

Thanks David
 
J

Jean-Guy Marcil

DavidUK said:
Hi,
What I want to do is create a macro button so that I can automatically
insert a comment field with some auto text in it. It works fine if I do it
manually – I can insert a comment into the text and then select the comment
field and place auto text into this. However, when I try to do this procedure
using a macro I get Run time error 5941 “The requested member of the
collection does not exist†Any ideas? I am using Word 2007.

I do not have my version of 2007 available right now, so I cannot test this
code. However, it does work with 2003. It might help you get going.


Dim cmtAutoText As Comment

Set cmtAutoText = Selection.Comments.Add(Range:=Selection.Range)

With cmtAutoText.Range
.Text = "Name_of_Autotext"
.InsertAutoText
End With

ActiveWindow.ActivePane.Close


The trick is to create and set an object of the type we need. It is much
easier to refer to it in the code afterwards (like my comment object above
named cmtAutotext).
 
Top