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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding out the pixel coordinates of text / hyperlinks in a word doc!

Status
Not open for further replies.

MastaMaikel

Programmer
Mar 5, 2004
2
DE
Hey People,

ich have got the following difficulties:
I need a Word-Macro that searches for hyperlinks in a word document, and finds out the exact position in pixes coordinates to the document top and left. (These Values need to be saved in a .ps (PostScript) file for converting into pdf file later...)

Everyone who can help me is the best!!! :)

Thanks a lot in advance...
Maikel
 
Hi MastaMaikel,

I don't think this is easy. You might be able to use the GetPoint Method of the Window, but it is screen-related (not document-related) and affected by, amongst other things, zoom factors. I couldn't make complete sense of it, but this might give you a start ..

Code:
[blue]Dim l As Long, t As Long, w As Long, g As Long
Dim H As Hyperlink
For Each H In ActiveDocument.Hyperlinks
    ActiveWindow.GetPoint l, t, w, g, H.Range
    MsgBox "Left:   " & l & " points " & PointsToCentimeters(l) & " cm" & vbNewLine & _
           "Top:    " & t & " points " & PointsToCentimeters(t) & " cm" & vbNewLine & _
           "Width:  " & w & " points " & PointsToCentimeters(w) & " cm" & vbNewLine & _
           "Height: " & g & " points " & PointsToCentimeters(g) & " cm"
Next[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Hey Tony, thanks a lot for the fast reply to my problem. You are right, I can find out the points related to the screen, but not the document itself. It is very strange that microsoft did not implent a way to find out the points related to the document. I already went through the whole help file but couldnt find any useful information.

But your code is a good beginning to the right direction :)

If anybody knows more information about that, please reply to this posting.

Thanks a lot
*Maikel*
 
Why not write the document to an EPS file ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Dear,

I have searched for the same issue for a long time.

I wonder if you have found a solution to get the coordinates of the hyperlinks/range relative to the top of the page.

thanks,
 
Hi Aj123,

Seems I didn't know how to do this last year. I do now - see my reply to your other post.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
There IS a way to measure the vertical distance in points, but I have not been able to figure out a way to measure the horizontal. Getting the horizontal margin, in points, is easy. But I have not been able to accurately get points out of making a Range from the start of the line to the locator at the hyperlink - or any other point really. The fact that it is a hyperlink is irrelevant. How do you get, count, points horizontally? I can get a character and space count no problem, but because of kerning ("i" is smaller than "w") how do you accurate determine points? My brain is tired, but there has to be a way. You real gurus figure it out.

Code:
Sub VerticalPoints()
Dim aDoc As Document
Dim aPara As Paragraph
Dim intFontSize As Integer
Dim r As Range
[COLOR=red]' set doc object and 
' make measurements in points
' go to first hyperlink and set a bookmark
' from that location to start of the page[/color red]
Set aDoc = ActiveDocument
Options.MeasurementUnit = wdPoints
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, _
    Count:=1, Name:="HYPERLINK"
aDoc.Bookmarks.Add Name:="temp", _
    Range:=Selection.Range
  Set r = aDoc.Range(Start:=aDoc.Bookmarks("\page").Range.Start, _
    End:=aDoc.Bookmarks("temp").Range.Start)
[COLOR=red]' as each paragraph may be a different
' font size, which affects the points
' loop through each paragraph add the size 
' IN POINTS[/color red]
For Each aPara In r.Paragraphs
    intFontSize = intFontSize + aPara.Range.Font.Size
Next

MsgBox "The vertical distance = " & _
   intFontSize + aDoc.PageSetup.HeaderDistance
Set r = Nothing
Set aDoc = Nothing
End Sub

Gerry
 
Hi Gerry,

For your, and others', benefit I have answered this in Aj123's new thread on the same question - thread707-1017402

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top