Marking text in a unique way

A

Andrew

Sorry, I hit 'Send' by accident :)
Here's the complete question:


I am exporting a document to another format in which I need to be able
to know which text is a hyperlink.
Because the export doesn't preserve hyperlinks, I need to find a way
to know when parsing the exported format, that a text is a hyperlink.

For instance, color can be one option but it's unreliable.
So is shading.

I have an idea with creating a floating picture shape and putting it
behind the hyperlink. But I canot place the picture programatically
where the text begin.

When parsing the exported format, I could see that the picture is near
the text and this will tell me text is a hyperlink.

I hope I succeeded to make you understand what I need to do.
 
G

Graham Mayor

I suppose you could add a unique string before and after the hyperlink e.g.

Dim oField As Range
For i = 1 To ActiveDocument.Fields.Count
ActiveDocument.Fields(i).Select
Set oField = Selection.Range
If ActiveDocument.Fields(i).Type = _
wdFieldHyperlink Then
oField.InsertBefore "&%&%&%"
oField.InsertAfter "&%&%&%"
End If
Next i

then remove it again from the other format.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Andrew

I suppose you could add a unique string before and after the hyperlink e.g.

Dim oField As Range
For i = 1 To ActiveDocument.Fields.Count
    ActiveDocument.Fields(i).Select
    Set oField = Selection.Range
    If ActiveDocument.Fields(i).Type = _
        wdFieldHyperlink Then
        oField.InsertBefore "&%&%&%"
        oField.InsertAfter "&%&%&%"
    End If
Next i

then remove it again from the other format.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Hi Graham,

I didn't think anyone would actually reply something to my question :)
Unfortunately text is what I first tried but it's not an option.
It ruins the formatting on the exported format.

I need something else, ingenious.
If I could put some picture like I described it would be perfect.
 
G

Graham Mayor

The idea was that you removed the added strings once imported into the other
application. However, the following will put an image behind the field -
here I used a smiley from my hard drive You could create a small block of
colour or whatever as a graphic and replace the path in the code.


Dim oField As Range
For i = 1 To ActiveDocument.Fields.Count
ActiveDocument.Fields(i).Select
Set oField = Selection.Range
If ActiveDocument.Fields(i).Type = _
wdFieldHyperlink Then
With ActiveDocument.Shapes.AddPicture(Anchor:=oField, _
FileName:="D:\My Documents\My Pictures\Animated GIFs\smile.gif",
_
LinkToFile:=False, _
SaveWithDocument:=True)
.WrapFormat.Type = 3
.ZOrder 5
End With
End If
Next i


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Andrew

The idea was that you removed the added strings once imported into the other
application. However, the following will put an image behind the field -
here I used a smiley from my hard drive You could create a small block of
colour or whatever as a graphic and replace the path in the code.

Dim oField As Range
For i = 1 To ActiveDocument.Fields.Count
    ActiveDocument.Fields(i).Select
    Set oField = Selection.Range
    If ActiveDocument.Fields(i).Type = _
        wdFieldHyperlink Then
        With ActiveDocument.Shapes.AddPicture(Anchor:=oField, _
            FileName:="D:\My Documents\My Pictures\AnimatedGIFs\smile.gif",
_
            LinkToFile:=False, _
            SaveWithDocument:=True)
            .WrapFormat.Type = 3
            .ZOrder 5
        End With
    End If
Next i

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Thanks Graham but the image is placed at the line start not when
behind the hyperlink text.
For example, create a new doc, type "ABC DEF" and then hyperlink only
"DEF". You will see that the image is placed behind "ABC".
I need to place the image behind or in front of the hyperlink text.

This is because when I parse the exported document, I am able to
figure out if an image is behind a text.
My idea is to generate dynamic images which have inside (at byte
level) as image content, the hyperlink address and tooltip text
string :)

Anyway, thanks a lot for your efforts.
 
G

Graham Mayor

If by 'behind' you mean 'underneath', rather than 'after', then I can't see
how it would be possible to do that in any way other than that I just posted
i.e. the image is placed in the graphics layer 'underneath' the text
anchored at the field position; and within the limitations inherent in
inserting graphics, is the size of the graphic.

If you mean 'after' then instead of inserting a floating image, you could
insert an in-line image, but then you would have the problem you complained
of earlier, in that the space occupied by the graphic would alter the text
layout.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Art H

Why not just apply a character style to the desired text and
experiment with different definitions of that character style (e.g.,
fonts, borders, underlining) until you get something that works.
 
F

fumei via OfficeKB.com

"Because the export doesn't preserve hyperlinks, I need to find a way
to know when parsing the exported format, that a text is a hyperlink."

This is a contradiction.

Say the text is "Microsoft", and the hyperlink Address is "
http://microsoft.com".

If the exported text "doesn't preserve hyperlinks"...then it doesn't. In
which case, the exported text - "Microsoft" - is NOT a hyperlink.

Let me see if I understand what you are actually asking.

You want some way of going through the exporting process and whenever it
finds text that is a hyperlink (and therefore it has the hyperlink character
style), create a dynamic graphical element under that text that will have the
VALUES of the hyperlink (e.g. "http://microsoft.com").

“My idea is to generate dynamic images which have inside (at byte
level) as image content, the hyperlink address and tooltip text
string :)â€

Hmmmm. I don’t think so.

As you have noted, using a Shape as a graphical element uses an anchor, and
that anchor is anchored to the start of the paragraph. The alternative, as
has been mentioned, is an InlineShape, but, again, as mentioned, brings you
back to a before/after situation.

“Unfortunately text is what I first tried but it's not an option.
It ruins the formatting on the exported format.â€

Huh? Really? Adding a string like “&%&%&%†is just adding a string. It
should not affect format in any way whatsoever. Could you elaborate on this?

I would have to agree with Art. You could identify text that is hyperlink
and then make your own character style for it. However, that does not solve
your requirement that you want the VALUES of the hyperlink…not just the text
that is the display text. Not only that, but you seem to want to create (and
therefore one would assume write to disk) a separate image file for each
found hyperlink. A separate image file that contains the values of the
hyperlink.

Interesting. What exactly is this export format?
 

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