R
ryguy7272
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
“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