Use variable with Count of GoTo Method of Word 2002 Macro?

G

Greg Strong

Why can't I use a variable for the count in the GoTo method to delete
merged text?

Basically the thought was to use a DoWhile Loop on a merged document to
go to the beginning of the second page of each section, go back 2 spaces
to get back to the end of the page 1 of that section and delete the text
on that line, then move on to the next section. The macro runs the
correct number of times, but the GoTo method is not moving past section
number 1. What I end up with is more deleted on the first page of the
first section rather the same codes on the first page of each section.

It appears the thought of using the "numCtr" on the "Count" of the GoTo
method is not working.

See the code below in the quote box with the question mark under the
questioned code. Any ideals? TIA!


,----- [ Macro ]
| Sub TestDeleteDocNo()
| '
| ' TestDeleteDocNo Macro
| ' Macro recorded 1/12/2004 by Greg Strong
| '
| Selection.EndKey Unit:=wdStory
| numRepeats = Selection.Information(wdActiveEndSectionNumber)
| Selection.HomeKey Unit:=wdStory
| numCtr = 1
|
| Do While numCtr < numRepeats
| Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=numCtr, Name:=""
| ?
|
| Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=2, Name:=""
| Selection.Find.ClearFormatting
| Selection.MoveLeft Unit:=wdCharacter, Count:=2
| Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
| Selection.Delete Unit:=wdCharacter, Count:=1
| Selection.HomeKey Unit:=wdStory
| numCtr = numCtr + 1
| Loop
|
| End Sub
`-----

Regards,


Greg Strong
 
G

Greg Strong

| Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=numCtr, Name:=""

The "numCtr" is the variable I was speaking about. Apparently the "?"
did not display properly. At least not on the web access to the
newsgroup.

Regards,


Greg Strong
 
H

Helmut Weber

Hi Greg,
I guess very much, it's:
Selection.GoTo What:=wdGoToPage, _
Which:=wdGoToFirst, Count:=2, Name:=""
which brings you always back to page 2.
The use of the variable is ok.
Try:
Selection.GoTo What:=wdGoToPage, _
Which:=wdGoToNext, _
Count:=1, Name:=""
which brings you to the second page in the selection,
which is a section.
And...
Selection.EndKey Unit:=wdStory
numRepeats = Selection.Information
(wdActiveEndSectionNumber)
or ...
ActiveDocument.Sections.Count
obviuosly does count the number of section.breaks.
I'd rather say, a document containing
7 sectionbreaks consists of 8 sections.
All in all moving the selection is not the best
approach. Try to get used to ranges.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word XP, NT 4.0
 
J

JGM

Hi Greg,

Please, do not multipost. If you feel you ned to post to many newsgroups, do
a crosspost, i.e. include all the NG names in the "To;" field when sending
it.

I just spend some time answering your question in the vba.beginners NG just
to see that Helmut as said more or less the same as I have, and he
mentionned the range object which Doug also mentionned in the other group...
it is kind of furtrating to realize that you have just taken the time to
answer a post that was already answered...

Cheers.
 
G

Greg Strong

Please, do not multipost. If you feel you ned to post to many newsgroups, do
a crosspost, i.e. include all the NG names in the "To;" field when sending
it.

In some newsgroups crossposting is FROWNED upon. I do apologize, and do
NOT mean to frustrate anyone. To be honest I didn't know about this
newsgroup until doing further research. In the future I will CROSSPOST
unless instructed otherwise. Again I do apologize.

Regards,


Greg Strong
 
J

Jonathan West

Greg Strong said:
In some newsgroups crossposting is FROWNED upon. I do apologize, and do
NOT mean to frustrate anyone. To be honest I didn't know about this
newsgroup until doing further research. In the future I will CROSSPOST
unless instructed otherwise. Again I do apologize.

Just so you are aware of the reasons why multiposting is frowned on even
more than crossposting, you might find the following article useful.

Tips from MVPs on posting to the Word newsgroups
http://www.mvps.org/word/FindHelp/Posting.htm
 

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