Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Need Word Macro Help Please

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alan B. Densky - 25 Apr 2007 02:52 GMT
Hello,

I have a macro that I've written with some help from others in this news
group. I have one last piece that I need help with.

The macro does a find and replace on a range of text.

After I do the find & replace, I need to select a range of text to copy to
the clip board.

I have to go back up to the top of the article (this is not the top of the
document because there is a string of hundreds of versions of the article in
this very long document.

Then I need to select a range of text (moving down in the document).

It would also be nice if I could copy that range to the clipboard.

Thanks in advance,
Alan

Here is what I have so far:

Sub LeaveLinks()
'
' LeaveLinks Macro
' Macro recorded 4/18/2007
'
'Find the string that starts the links block of text and delete the text on
that line
 Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
       .Text = "LINKS SECTION======"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindAsk
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute
   With Selection
       If .Find.Forward = True Then
           .Collapse Direction:=wdCollapseStart
       Else
           .Collapse Direction:=wdCollapseEnd
       End If
       .Find.Execute Replace:=wdReplaceOne
       If .Find.Forward = True Then
           .Collapse Direction:=wdCollapseEnd
       Else
           .Collapse Direction:=wdCollapseStart
       End If
       .Find.Execute
   End With

'Delete the block of text that doesn't have any links in it
Dim oRg As Range
Set oRg = ActiveDocument.Range
    With oRg.Find
       .ClearFormatting
       .Replacement.ClearFormatting
       .Text = "(NO LINKS SECTION======)(*)(END NO LINKS SECTION======)"
       .Replacement.Text = ""
       .Forward = True
       .Format = False
       .MatchWildcards = True
       .Wrap = wdFindContinue
       .Execute Replace:=Word.WdReplace.wdReplaceOne
   End With

'Go back up and find the beginning of the article

 Selection.Find.ClearFormatting
   With Selection.Find
       .Text = "Article With Back links"
       .Replacement.Text = ""
       .Forward = False
       .Wrap = wdFindAsk
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute

'Select the range of text to copy to the clipboard
   With oRg.Find
       .ClearFormatting
       .Replacement.ClearFormatting
       .Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"
    '  ' .Replacement.Text = ""
       .Forward = True
       .Format = False
       .MatchWildcards = True
       .Wrap = wdFindContinue
       .Execute Replace:=Word.WdReplace.wdReplaceOne
   End With

'Copy the selected range to the clipboard

End Sub
Cindy M. - 26 Apr 2007 12:39 GMT
Hi Alan,

> The macro does a find and replace on a range of text.
>  
[quoted text clipped - 8 lines]
>  
> It would also be nice if I could copy that range to the clipboard.

You need to decide how you can determine the starting and end-points of this
range. How can they be identified?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Alan B. Densky - 26 Apr 2007 13:52 GMT
Hi Cindy,

If you look at the macro (as I've written it so far), you can see that I
have indicated the starting and ending points in it:

.Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"

What I don't know how to do is to copy that selection to the clipboard
instead of replacing the text. Can you help?

Thanks,

Alan

The Part Of The Marco That I Am Lost On:

'Select the range of text to copy to the clipboard
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"
' ' .Replacement.Text = ""
.Forward = True
.Format = False
.MatchWildcards = True
.Wrap = wdFindContinue
.Execute Replace:=Word.WdReplace.wdReplaceOne
End With

'Copy the selected range to the clipboard

ENTIRE MACRO

Sub LeaveLinks()
'
' LeaveLinks Macro
' Macro recorded 4/18/2007
'
'Find the string that starts the links block of text and delete the text on
that line
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "LINKS SECTION======"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With

'Delete the block of text that doesn't have any links in it
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(NO LINKS SECTION======)(*)(END NO LINKS SECTION======)"
.Replacement.Text = ""
.Forward = True
.Format = False
.MatchWildcards = True
.Wrap = wdFindContinue
.Execute Replace:=Word.WdReplace.wdReplaceOne
End With

'Go back up and find the beginning of the article

Selection.Find.ClearFormatting
With Selection.Find
.Text = "Article With Back links"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

'Select the range of text to copy to the clipboard
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"
' ' .Replacement.Text = ""
.Forward = True
.Format = False
.MatchWildcards = True
.Wrap = wdFindContinue
.Execute Replace:=Word.WdReplace.wdReplaceOne
End With

'Copy the selected range to the clipboard

End Sub

> Hello,
>
[quoted text clipped - 25 lines]
> '
> 'Find the string that starts the links block of text and delete the text
on
> that line
>   Selection.Find.ClearFormatting
[quoted text clipped - 64 lines]
>         .Replacement.ClearFormatting
>         .Text = "(Article With Back links)(*)(END NO LINKS
SECTION======2)"
>      '  ' .Replacement.Text = ""
>         .Forward = True
[quoted text clipped - 7 lines]
>
> End Sub

> Hi Alan,
>
[quoted text clipped - 21 lines]
> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)
Alan B. Densky - 26 Apr 2007 13:51 GMT
Hi Cindy,

If you look at the macro (as I've written it so far), you can see that I
have indicated the starting and ending points in it:

.Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"

What I don't know how to do is to copy that selection to the clipboard
instead of replacing the text. Can you help?

Thanks,

Alan

The Part Of The Marco That I Am Lost On:

'Select the range of text to copy to the clipboard
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"
' ' .Replacement.Text = ""
.Forward = True
.Format = False
.MatchWildcards = True
.Wrap = wdFindContinue
.Execute Replace:=Word.WdReplace.wdReplaceOne
End With

'Copy the selected range to the clipboard

ENTIRE MACRO

Sub LeaveLinks()
'
' LeaveLinks Macro
' Macro recorded 4/18/2007
'
'Find the string that starts the links block of text and delete the text on
that line
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "LINKS SECTION======"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With

'Delete the block of text that doesn't have any links in it
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(NO LINKS SECTION======)(*)(END NO LINKS SECTION======)"
.Replacement.Text = ""
.Forward = True
.Format = False
.MatchWildcards = True
.Wrap = wdFindContinue
.Execute Replace:=Word.WdReplace.wdReplaceOne
End With

'Go back up and find the beginning of the article

Selection.Find.ClearFormatting
With Selection.Find
.Text = "Article With Back links"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

'Select the range of text to copy to the clipboard
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"
' ' .Replacement.Text = ""
.Forward = True
.Format = False
.MatchWildcards = True
.Wrap = wdFindContinue
.Execute Replace:=Word.WdReplace.wdReplaceOne
End With

'Copy the selected range to the clipboard

End Sub

> Hello,
>
[quoted text clipped - 104 lines]
>
> End Sub
Cindy M. - 26 Apr 2007 14:54 GMT
Hi Alan,

> What I don't know how to do is to copy that selection to the clipboard
> instead of replacing the text.

Selection.Copy or oRng.Copy should work.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
Alan B. Densky - 26 Apr 2007 20:33 GMT
Hi Cindy,

No, that doesn't work. there is no oRng.Copy

And Selection.Copy might work, if the text was selected. But it
isn't.because the Find isn't executed. If I could figure out how to do
something like .Execute Find - it might work.

Alan

> Hi Alan,
>
[quoted text clipped - 10 lines]
> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)
Helmut Weber - 26 Apr 2007 21:33 GMT
Hi Alan,

maybe like this:

Sub T5()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
  .Text = "xxx*yyy"
  .MatchWildcards = True
  If .Execute Then
     rDcm.Select ' for testing, remove later
     rDcm.Copy
     rDcm.Text = ""
  End If
End With
End Sub

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Jean-Guy Marcil - 26 Apr 2007 21:35 GMT
Alan B. Densky was telling us:
Alan B. Densky nous racontait que :

> Hi Cindy,
>
[quoted text clipped - 26 lines]
>
> 'Copy the selected range to the clipboard

Why do you want to copy the found text to the clipboard?
It is usually better to leave the clipboard as is, unless there is no other
way. Since I do not know what you intend to do with this found text, I
cannot say if there is a better way to proceed.

Meanwhile, what you need is something like:

'_______________________________________
With oRg.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"
   .Forward = True
   .Format = False
   .MatchWildcards = False
   .Wrap = wdFindContinue
   .Execute
   With .Parent
       .Copy
   End With
End With
'_______________________________________

I am not sure, but I think that you do not need to set Wildcard to true, if
you, the "(" or ")" will not be part of the found text.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Alan B. Densky - 27 Apr 2007 00:27 GMT
Hi Jean Guy,

I want to copy that range of text to the clip board because I will be
pasting it into another application on a web page.

I get an error 4605 on the .Copy - > "This method or property is not
available because no text is selected"

Can you help?

Thanks!

Alan

> Alan B. Densky was telling us:
> Alan B. Densky nous racontait que :
[quoted text clipped - 55 lines]
> I am not sure, but I think that you do not need to set Wildcard to true,
> if you, the "(" or ")" will not be part of the found text.
Jean-Guy Marcil - 27 Apr 2007 00:59 GMT
Alan B. Densky was telling us:
Alan B. Densky nous racontait que :

> Hi Jean Guy,
>
[quoted text clipped - 5 lines]
>
> Can you help?

Without seeing your code, no, not really...

But, if you are using the code exactly as I have posted it, you may be
having a case of bad Find/Replace karma..
See:
   http://word.mvps.org/faqs/macrosvba/FlushFR.htm

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Alan B. Densky - 27 Apr 2007 01:45 GMT
Hi,

I've got things working, sort of. But I have a problem. I tried the advice
in the bad find karma, but it had no effect.

My macro works correctly and does what I want until it gets to the label
[Works Okay To Here]. The insertion point is at the top of the section of
the document where I want it. But when it executs the code from that point,
instead of selecting the range as defined in the macro, it skips that range
and goes on down the document and selects the next range that matches the
criteria. I've messed with the .Forward=True in that part of the macro to
see what would happen, but it has no effect on it at all.

Any ideas?

Alan

'Find the string that starts the links block of text and delete the text on
that line
 Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
       .Text = "LINKS SECTION======"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindAsk
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute
   With Selection
       If .Find.Forward = True Then
           .Collapse Direction:=wdCollapseStart
       Else
           .Collapse Direction:=wdCollapseEnd
       End If
       .Find.Execute Replace:=wdReplaceOne
       If .Find.Forward = True Then
           .Collapse Direction:=wdCollapseEnd
       Else
           .Collapse Direction:=wdCollapseStart
       End If
       .Find.Execute
   End With

'Delete the block of text that doesn't have any links in it
Dim oRg As Range
Set oRg = ActiveDocument.Range
    With oRg.Find
       .ClearFormatting
       .Replacement.ClearFormatting
       .Text = "(NO LINKS SECTION======)(*)(END NO LINKS SECTION======)"
       .Replacement.Text = ""
       .Forward = True
       .Format = False
       .MatchWildcards = True
       .Wrap = wdFindContinue
       .Execute Replace:=Word.WdReplace.wdReplaceOne
   End With

'Go back up and find the beginning of the article

 Selection.Find.ClearFormatting
   With Selection.Find
       .Text = "Article With Back links"
       .Replacement.Text = ""
       .Forward = False
       .Wrap = wdFindAsk
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute
   Selection.MoveDown Unit:=wdLine, Count:=1

[Works Okay To Here]

    'Copy the selected range to the clipboard
   With oRg.Find
       .ClearFormatting
       .Replacement.ClearFormatting
       .Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"
       .Forward = True
       .MatchWildcards = True
      If .Execute Then
         oRg.Select ' for testing, remove later
        ' oRg.Copy
        ' oRg.Text = ""
      End If
   End With

> Alan B. Densky was telling us:
> Alan B. Densky nous racontait que :
[quoted text clipped - 15 lines]
> See:
>    http://word.mvps.org/faqs/macrosvba/FlushFR.htm
Jean-Guy Marcil - 27 Apr 2007 15:52 GMT
Alan B. Densky was telling us:
Alan B. Densky nous racontait que :

> Hi,
>
[quoted text clipped - 93 lines]
>       End If
>    End With

It is always a bit messy to use alternatively Range and Selection objects.
You should only use one of them, unless you have no other choice. The
Range.Find object allows you to manipulate the document content without
touching at the user selection point and will not leave any settings behind
in the Find/Replace dialog box when the user next uses it, but it can a bit
a bit ore obscure and difficult to get used to. If you need both, you have
to be extra careful and make sure you know what is going on in the document.
One trick you can use is to set the Word document window to half the screen
(Horizontally) and the VBA code window to the other half. Then, place the
cursor inside the code and hit F8 to debug step by step. Every time you hit
F8, one line of code gets executed and you can see the changes, if any, in
the document above.

In your particular case, what I can see is this:

You start with this:
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
   ...
which works form the user current selection and will change that selection
if the text is found. The found text becomes the current selection.
Let's say the text has been found and the selection was consequently
changed.
Next, you use a bunch of If statements to change the current selection.
This is followed by:
   Dim oRg As Range
   Set oRg = ActiveDocument.Range
   With oRg.Find
   ...
This works on the whole document and will act on the first instance fund in
the document, regardless of the current selection.
And then you do:
   Selection.Find.ClearFormatting
   With Selection.Find
   .Text = "Article With Back links"
which will again move the selection if the text is found. Let's say it was.
You finish with:
   With oRg.Find
   .ClearFormatting
   .Replacement.ClearFormatting
Here oRg refers to the range that was found before, and deleted! So, now it
refers to nothing, so unsurprisingly, nothing is found. How did you expect
to copy something that was deleted to the clipboard? I am a bit confused by
your procedure. Maybe you need to add
   Set oRg = ActiveDocument.Range
before this last oRg.Find to reset the range to the whole document. Remember
that a Range.Find.Execute will not change the selection in the document but
will change the Range object if the text is found.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Alan B. Densky - 28 Apr 2007 04:45 GMT
Hi Jean-Guy,

Excellent! That is what it needed. Now I have one more question, and then
this macro is perfect.

Now I've selected the range and I've copied it to the clipboard. But how can
I get it to NOT copy the start marker and the end marker? In other words, I
need it to start selecting one line below the Start Marker, and end up one
line above the End Marker.

This way I get only the text between the two markers, which is what I really
want. Otherwise I'll have to manually delete the Start Marker and the End
Marker after I've pasted the text into the other application.

Thanks!!

Alan

> Alan B. Densky was telling us:
> Alan B. Densky nous racontait que :
[quoted text clipped - 148 lines]
> Remember that a Range.Find.Execute will not change the selection in the
> document but will change the Range object if the text is found.
Jean-Guy Marcil - 28 Apr 2007 18:38 GMT
Alan B. Densky was telling us:
Alan B. Densky nous racontait que :

> Hi Jean-Guy,
>
[quoted text clipped - 10 lines]
> and the End Marker after I've pasted the text into the other
> application.

You seem to be implying the start marker is followed by a ¶ which should not
be part of the copied text to the clipboard. Is that right?

Show us the code that you decided to use to actually select/copy your target
text.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Alan B. Densky - 28 Apr 2007 20:20 GMT
Hi Jean-Guy,

What I'm saying is that the start and end markers are strings of text that I
don't want to copy to the clipboard. They are there for the sole purpose of
making the macro universal so that it will work with every article that I
create.

Some article directories allow you to have links in the body of your
article, and some don't. So I write the article with a block of text that
has the links, and then repeat the same block of text without the links. The
macro allows me to instantly edit out the links, or leave them in. This is
the macro that deletes out the block of text without the links, and then
copies the article to the clipboard so that I can paste it into the
appropriate field in the article directory.

Thanks for your help,

Alan

Sub LeaveLinks()
'
' LeaveLinks Macro
' Macro recorded 4/18/2007
'
'Find the string that starts the links block of text and delete the text on
that line
 Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
       .Text = "LINKS SECTION======"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindAsk
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute
   With Selection
       If .Find.Forward = True Then
           .Collapse Direction:=wdCollapseStart
       Else
           .Collapse Direction:=wdCollapseEnd
       End If
       .Find.Execute Replace:=wdReplaceOne
       If .Find.Forward = True Then
           .Collapse Direction:=wdCollapseEnd
       Else
           .Collapse Direction:=wdCollapseStart
       End If
       .Find.Execute
   End With

'Delete the block of text that doesn't have any links in it
Dim oRg As Range
Set oRg = ActiveDocument.Range
    With oRg.Find
       .ClearFormatting
       .Replacement.ClearFormatting
       .Text = "(NO LINKS SECTION======)(*)(END NO LINKS SECTION======)"
       .Replacement.Text = ""
       .Forward = True
       .Format = False
       .MatchWildcards = True
       .Wrap = wdFindContinue
       .Execute Replace:=Word.WdReplace.wdReplaceOne
   End With

'Go back up and find the beginning of the article

 Selection.Find.ClearFormatting
   With Selection.Find
       .Text = "Article With Back links"
       .Replacement.Text = ""
       .Forward = False
       .Wrap = wdFindAsk
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute
   Selection.MoveUp Unit:=wdLine, Count:=1

 Set oRg = ActiveDocument.Range

'Select the range of text to copy to the clipboard
   With oRg.Find
       .ClearFormatting
       .Replacement.ClearFormatting
       .Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"
       .Replacement.Text = ""
       .Forward = True
       .Format = False
       .MatchWildcards = True
       .Wrap = wdFindContinue
       .Execute
      With .Parent
           .Select
           .Copy
       End With
   End With

   ActiveDocument.Save
End Sub

> Alan B. Densky was telling us:
> Alan B. Densky nous racontait que :
[quoted text clipped - 19 lines]
> Show us the code that you decided to use to actually select/copy your
> target text.
Jean-Guy Marcil - 29 Apr 2007 03:27 GMT
Alan B. Densky was telling us:
Alan B. Densky nous racontait que :

> Hi Jean-Guy,
>
> What I'm saying is that the start and end markers are strings of text
> that I don't want to copy to the clipboard. They are there for the
> sole purpose of making the macro universal so that it will work with
> every article that I create.

I understood that part, I was just asking if the start tag was always
followed by a ¶, in which case it should also be removed from the text to be
copied as it would not serve any purpose once the tag is removed.

Here's the code you can use:

'_______________________________________
Set oRg = ActiveDocument.Range

'Select the range of text to copy to the clipboard
With oRg.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Text = "(Article With Back links)(*)(END NO LINKS SECTION======2)"
   .Replacement.Text = ""
   .Forward = True
   .Format = False
   .MatchWildcards = True
   .Wrap = wdFindContinue
   .Execute
  With .Parent
       .MoveStart wdWord, 4
       .MoveEnd wdWord, -6
       .Copy
   End With
End With
'_______________________________________

If the start tag is always followed by a ¶, change
    .MoveStart wdWord, 4
by
   .MoveStart wdWord, 5

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Alan B. Densky - 29 Apr 2007 05:43 GMT
Hi,

Yes, it is always followed by a ¶. In any case, the macro is now perfect.
Thank you very much for all of your help.

I'm actually an MS Access/VBA programmer with 14 years of experience. And
besides being out of my element with Word, one of the things that made it
difficult for me is that I couldn't find any info on the web to help me with
this particular problem.

Since this is probably a one time thing, I wasn't going to spend $50.00 on a
book to learn how to program Word. I felt like it was 1993 and I was
learning Access from scratch again. I didn't even know what to try to look
up then.

Again, thanks for your kind assistance.

Alan

> Alan B. Densky was telling us:
> Alan B. Densky nous racontait que :
[quoted text clipped - 38 lines]
> by
>    .MoveStart wdWord, 5
The Harbour School - 12 Jun 2007 17:39 GMT
On 4/28/07 10:27 PM, in article #BXn7XgiHHA.3412@TK2MSFTNGP02.phx.gbl,

> Alan B. Densky was telling us:
> Alan B. Densky nous racontait que :
[quoted text clipped - 38 lines]
> by
>     .MoveStart wdWord, 5
kjuuuuity7it
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.