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 / October 2007

Tip: Looking for answers? Try searching our database.

Find String, Copy/Paste Next 255+ Characters to New .doc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ryguy7272 - 18 Oct 2007 15:36 GMT
Does anyone know of a way to search for a certain string, such as
“Additional” and then copy/paste this into a new document, along with the
following 255 characters?  Is 255 the limit?  I found the code below on this
DG:

Sub RTM4()
Dim oDoc As Document
Dim oSrcRg As Range, oDestRg As Range

Set oSrcRg = ActiveDocument.Range
Set oDoc = Documents.Add
Set oDestRg = oDoc.Range
oDestRg.Collapse wdCollapseEnd

With oSrcRg.Find
.ClearFormatting
.Text = "Additional ?{255}"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

Do While .Execute
oDestRg.FormattedText = oSrcRg.FormattedText
oDestRg.Collapse wdCollapseEnd
oDestRg.InsertParagraph
oDestRg.Collapse wdCollapseEnd
Loop
End With

Set oDestRg = oDoc.Range
oDestRg.ConvertToTable Separator:=wdSeparateByTabs, _
NumColumns:=3, NumRows:=100, _
AutoFitBehavior:=wdAutoFitFixed
With oDoc.Tables(1)
.Style = "Table Grid"
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With

oDoc.Activate

Set oSrcRg = Nothing
Set oDestRg = Nothing
Set oDoc = Nothing
End Sub

It works great.  Sometimes the string, such as “Additional” is in a table,
and the code seems to struggle with the tables sometimes.  For instance, if I
have the word “Additional” in one table, I'd like to find 255 characters, or
more, up to 500 characters, in an adjacent table, just to the right on this
table.  Any suggestions?

Regards,
Ryan

Signature

RyGuy

Russ - 21 Oct 2007 23:31 GMT
Ryan,
In regards to find string in a table across cells, you could temporarily
convert the table range to text, use your find your search criteria- copy
and paste loop, and change table range back to table. Since you are not
altering the table, it should survive a change to text and back to table
without incident.

In the find text box there might be a limit of 255 characters that you can
find **literally**, but if you use the find textbox while using the
wildcards function you effectively get passed finding only 255 characters at
the most. You must come up with a unique find start and end pattern.
http://www.gmayor.com/replace_using_wildcards.htm

You are being too vague on the ending delimiter of your search range. You
can find a certain pattern then use the .extend or .expand method while in
the found loop. But while using VBA code you need to come up with a unique
ending pattern or one certain character count limit or limit it to a certain
amount of words, cells, paragraphs, sections, etc. after the initial
starting found text. (Unless you allow user input while running the macro to
change the starting and ending criteria on the fly.)

> Does anyone know of a way to search for a certain string, such as
> ³Additional² and then copy/paste this into a new document, along with the
[quoted text clipped - 71 lines]
> Regards,
> Ryan

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

ryguy7272 - 22 Oct 2007 21:56 GMT
Thanks for the look Russ.  I’m intrigued, but I don’t know how to implement
what you suggested.  Do you know how to approach this task?  I seriously
doubt the macro recorder will create me the code that gives me what I need.

Now I’m lost.

Any additional help would be greatly appreciated.
Ryan--

Signature

RyGuy

> Ryan,
> In regards to find string in a table across cells, you could temporarily
[quoted text clipped - 92 lines]
> > Regards,
> > Ryan
Russ - 23 Oct 2007 06:19 GMT
Ryan,
As I said, you need to determine unique patterns to search for.

The macro recorder can help get you started sometimes:
I.e., It can show you the VBA code used to convert a table to text and then
back from text to table.
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm

Help on using wildcards:
http://www.word.mvps.org/FAQs/General/UsingWildcards.htm
http://www.word.mvps.org/FAQs/General/FindingSpecialCharacters.htm
http://www.gmayor.com/replace_using_wildcards.htm

Example of find then do something besides standard replacement of found
text:
http://word.mvps.org/faqs/macrosvba/ReplceTextWithDoc.htm

After reading the above links and other pages they may branch off to, If you
have a specific question, then by all means, post another message. But at
least tell us what you have tried and didn't get to work.

> Thanks for the look Russ.  I¹m intrigued, but I don¹t know how to implement
> what you suggested.  Do you know how to approach this task?  I seriously
[quoted text clipped - 4 lines]
> Any additional help would be greatly appreciated.
> Ryan--

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
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.