Insert Autotext

S

Steved

Hello from Steved

When I run the Macro its asks to be debugged it Highlites below
What Have I not done please.

Yes I want it to Execute "Win"

ActiveDocument.AttachedTemplate.AutoTextEntries("Win").Insert


Sub ScracthMacro()
Dim oRng As Word.Range
Dim i As Long
Dim j As Long
Dim count As Long
count = ActiveDocument.ComputeStatistics(wdStatisticPages)
Set oRng = ActiveDocument.Range
oRng.Collapse wdCollapseStart
oRng.Select
For j = 1 To count
i = Selection.Bookmarks("\Page").Range.Paragraphs.Last.Range.Start
oRng.Start = i
oRng.Select
ActiveDocument.AttachedTemplate.AutoTextEntries("Win").Insert
Selection.MoveDown wdParagraph, 1
Set oRng = Selection.Range
Next j
End Sub

Thankyou.
 
G

Gordon Bentley-Mix on news.microsoft.com

See the VBA Help topic on the Insert Method, specifically as it applies to
the AutoTextEntry object. I believe you will find that 'Where' is a required
argument for this method when used with this particular object. Accordingly,
simply rewriting the problem line of code as:

ActiveDocument.AttachedTemplate.AutoTextEntries("Win").Insert oRng

should do the trick. (For the purposes of this discussion I'll ignore the
rest of your code and your apparent random use of the Selection object and
Select method, as it's a complete mystery to me just exactly what it is that
you're trying to do...)
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
S

Steved

Hello Gordon from Steved

Firstly thankyou.

I copied your script into my maco and it just Highlights it.

What's my object

On each page find the last paragraph insert "win" using autotext command.
It inserts six boxes together on the same line, Then finds the next page and
repeats until there are no more pages.

hopefully I've explained.

Thankyou.
 
S

Steved

Hello from Steved

the below works but i have to do it page by page, I want it to loop please.

Sub RaceTemplate()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[0-9]{1,2}:[0-9]{2}[ ^s]{1,}RACE"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection.Find
.Text = "^12"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.MoveUp Unit:=wdLine, count:=2
Selection.TypeText Text:="win"
Selection.Range.InsertAutoText
End Sub
 
P

Pesach Shelnitz

Hi Steved,

You need a loop as you had in the Boxed macro that you wrote in a previous
post. In other words, you need to include the the following lines from the
Boxed macro at the beginning and end of this macro.
Do
....
Loop While Selection.Find.Found

It seems to me that you are trying to use pieces of recorded macros in your
code and do things yourself using code that you understand. That's fine, and
it's a great way to start learning to write more advanced macros, but you
should be aware that there are often better ways to do things. One thing in
particular that you should learn about is the Range object and the advantages
that it offers when you have repeated searches in a macro. Your macros use
the Selection object. The Selection object represents the insertion point or
the selected text. When you use the Selection object, all the cursor
movements need to be displayed on the screen. This may not be important in a
short document, but in large documents this can noticeably slow down the
macro. The Range object provides a way to move around the document without
displaying the movement and can greatly improve performance.

--
Hope this helps,
Pesach Shelnitz


Steved said:
Hello from Steved

the below works but i have to do it page by page, I want it to loop please.

Sub RaceTemplate()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[0-9]{1,2}:[0-9]{2}[ ^s]{1,}RACE"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection.Find
.Text = "^12"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.MoveUp Unit:=wdLine, count:=2
Selection.TypeText Text:="win"
Selection.Range.InsertAutoText
End Sub


Gordon Bentley-Mix on news.microsoft.com said:
See the VBA Help topic on the Insert Method, specifically as it applies to
the AutoTextEntry object. I believe you will find that 'Where' is a required
argument for this method when used with this particular object. Accordingly,
simply rewriting the problem line of code as:

ActiveDocument.AttachedTemplate.AutoTextEntries("Win").Insert oRng

should do the trick. (For the purposes of this discussion I'll ignore the
rest of your code and your apparent random use of the Selection object and
Select method, as it's a complete mystery to me just exactly what it is that
you're trying to do...)
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
S

Steved

Hello Pesach

Thankyou

Pesach Shelnitz said:
Hi Steved,

You need a loop as you had in the Boxed macro that you wrote in a previous
post. In other words, you need to include the the following lines from the
Boxed macro at the beginning and end of this macro.
Do
...
Loop While Selection.Find.Found

It seems to me that you are trying to use pieces of recorded macros in your
code and do things yourself using code that you understand. That's fine, and
it's a great way to start learning to write more advanced macros, but you
should be aware that there are often better ways to do things. One thing in
particular that you should learn about is the Range object and the advantages
that it offers when you have repeated searches in a macro. Your macros use
the Selection object. The Selection object represents the insertion point or
the selected text. When you use the Selection object, all the cursor
movements need to be displayed on the screen. This may not be important in a
short document, but in large documents this can noticeably slow down the
macro. The Range object provides a way to move around the document without
displaying the movement and can greatly improve performance.

--
Hope this helps,
Pesach Shelnitz


Steved said:
Hello from Steved

the below works but i have to do it page by page, I want it to loop please.

Sub RaceTemplate()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[0-9]{1,2}:[0-9]{2}[ ^s]{1,}RACE"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection.Find
.Text = "^12"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.MoveUp Unit:=wdLine, count:=2
Selection.TypeText Text:="win"
Selection.Range.InsertAutoText
End Sub


Gordon Bentley-Mix on news.microsoft.com said:
See the VBA Help topic on the Insert Method, specifically as it applies to
the AutoTextEntry object. I believe you will find that 'Where' is a required
argument for this method when used with this particular object. Accordingly,
simply rewriting the problem line of code as:

ActiveDocument.AttachedTemplate.AutoTextEntries("Win").Insert oRng

should do the trick. (For the purposes of this discussion I'll ignore the
rest of your code and your apparent random use of the Selection object and
Select method, as it's a complete mystery to me just exactly what it is that
you're trying to do...)
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!


:

Hello from Steved

When I run the Macro its asks to be debugged it Highlites below
What Have I not done please.

Yes I want it to Execute "Win"

ActiveDocument.AttachedTemplate.AutoTextEntries("Win").Insert


Sub ScracthMacro()
Dim oRng As Word.Range
Dim i As Long
Dim j As Long
Dim count As Long
count = ActiveDocument.ComputeStatistics(wdStatisticPages)
Set oRng = ActiveDocument.Range
oRng.Collapse wdCollapseStart
oRng.Select
For j = 1 To count
i = Selection.Bookmarks("\Page").Range.Paragraphs.Last.Range.Start
oRng.Start = i
oRng.Select
ActiveDocument.AttachedTemplate.AutoTextEntries("Win").Insert
Selection.MoveDown wdParagraph, 1
Set oRng = Selection.Range
Next j
End Sub

Thankyou.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top