Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tricky macro problem

Status
Not open for further replies.

artj

Technical User
Oct 28, 2003
13
US
I'm trying to create a macro that finds a string of text with unique formatting and line spacing, and then convert it to a link. It would not be all that tricky except for the fact that some of these strings of text are broken by a paragraph mark in the middle. For example, "Accessing the Internet" and "from your easy chair" are separated by a paragraph return. I want to create a link for "Accessing the Internet from your easy chair". Both strings have the same font formatting and line spacing.

Unfortunately, it's not the only instance of a single paragraph mark so that line of attack has so far proven useless. As I mentioned, the only unique characteristics are the combined font formatting and line spacing.

Can anyone suggest some code to remove thatparagraph mark from between the two strings of text?

Thanks
AJ
 
artj,

The strings are not "broken' by paragraph marks, it is CHR(10) line feed character. You could do
Code:
=SUBSTITUTE(C4,CHAR(10)," ")
where C4 has such a string and the result will display without the line feeds.

do this for whatever columns you have this case, copy the column with this formula and pastespecial - values

and VOLA!

copy back over if you wish :)

Skip,
Skip@TheOfficeExperts.com
 
Skip, thanks for the code. Unfortunately, I forgot to mention two key pieces of information.

1. I'm working in Word 2k
2. The strings are always different

AJ
 
Okay, so define your problem more clearly. You have a word document. In what format is the text you're searching for? A string variable? Could the paragraph end be anywhere between any of the words you are searching for?


Rob
[flowerface]
 
Rob,

Unfortunately, the only criteria I have for finding the string is the font formatting (i.e. Arial, 10pt, not bold, not italic, rgb(0,127,0))which is unique to these "links". And yes, the paragraph mark can be between any of the words. Finally, some strings have the paragraph mark and others don't.

AJ
 
Then you could just search for the font formatting, and extend the selection until this formatting changes, no?

Rob
[flowerface]
 
A rather crude example:
Code:
Sub try()
   Dim r As Long, f As Boolean
   Do
      With Selection.Find
         .Font.Bold = True
         .Execute
         f = .Found
      End With
      If f Then
         r = Selection.Start
         Do While Selection.Font.Bold
            Selection.Move wdCharacter, 1
         Loop
         ActiveDocument.Range(r, Selection.Start).Font.Color = wdColorGreen
      End If
   Loop While f
End Sub


Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top