PDA

View Full Version : Solved: Convert word in hyperlink



Pasquale
08-14-2005, 10:29 AM
Hallo, J have again help for biblical study.

J have to Hyperlink all word inserted in square bracket [ ] into a Hyperlink to open a software.

Sample [Gen 11:26] Hyperlink in this case is: javascript:BwGoToVerse('Gen%2011:26') and so on. Dysplay [Gen 11:26]

Therefore the hyperlink must have the same reference word and number inserted in square bracket.
The reference can be also with two number, sample: javascript:BwGoToVerse('Mat%2012:14-20'). The Dysplay text is the same.

thanks pasquale

P.S J have changed the file and the txt of the post.

:think: :think:

TonyJollans
08-16-2005, 05:20 AM
Hi Pasquale,

I think this will do it ...

Sub Macro1()

Selection.HomeKey wdStory

Selection.Find.ClearFormatting
With Selection.Find
.Text = "\[* [0-9]{1,}:[0-9]{1,}\]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With

While Selection.Find.Execute
Selection.Hyperlinks.Add Anchor:=Selection.Range, _
TextToDisplay:=Selection.Range.Text, _
Address:="javascript:BwGoToVerse('" & Selection.Range.Text & "')"
Wend

End Sub

Pasquale
08-16-2005, 06:46 AM
Hi Tony
thanks for macro, Perhaps there is an error.
Debug:Error Run Time "5560";
"The script in square find have a not valid word"

J post a translation of my original post translated by XCave8r:

I need to create a hypertext link for each reference to a chapter and verse that appears in the text. These references are enclosed in square brackets as in [Gen 11:26]. I need to make this text point to the chapter in each verse referenced. So, using [Gen 11:26] as an example, I need the link for this text to be in the following format:





Code:
javascript:BwGoToVerse('Gen11:26')



Each reference is in the following format: [AAA ##0:##0]. The book's name is always abbreviated to the three letters. It's followed by a single space and then the chapter number, which can be up to three digits long. The chapter number is followed by a colon; the colon is followed by the verse number, which can be up to three digits long.

More examples:

[Gen 1:1]





Code:
javascript:BwGoToVerse('Gen1:1')



[Gen 100:100]





Code:
javascript:BwGoToVerse('Gen100:100')


Pasquale

xCav8r
08-16-2005, 06:58 AM
I think my translation might have come a little too late. Tony, it looks like what you made does what he's looking for.

TonyJollans
08-16-2005, 07:02 AM
Hi Pasquale,

I don't get any errors and I don't recognise the error number or your translation of the error message as anything I've seen before. What line of code does the error happen on? And what version of Word are you using?

Pasquale
08-16-2005, 07:24 AM
Jellow line in debug

While Selection.Find.Execute

pasquale

Pasquale
08-16-2005, 07:25 AM
Hi Tony

Word 2003

pasquale

Pasquale
08-16-2005, 07:32 AM
Hi Tony

Errore di Run time "5560"

Il testo nella casella Trova contiene una espressione non valida Usa criteri di ricerca

Pheraps is italian microsoft word that is different?
Pasquale

TonyJollans
08-16-2005, 08:07 AM
Hi Pasquale,

I am using 2003 too so no difference there.

I recorded the Find to get the code quickly - then just added the hyperlink bit.

Perhaps you could try recording it and see if it gives anything different. The Find what text is \[* [0-9]{1,}:[0-9]{1,}\] and you need to check "Use Wildcards" (I don't know the Italian :))

TonyJollans
08-16-2005, 08:23 AM
Hi Pasquale,

The error message in English is "The Find What text contains a Pattern Match expression which is not valid"

Does some international setting affect the use of commas perhaps? This is a complete guess but try using semicolons (";") instead of commas (",")

Pasquale
08-16-2005, 09:29 AM
Hi Tony

Using semicolons (";") instead of commas (",") now work very well. J test the macro

pasquale

Pasquale
08-16-2005, 09:46 AM
Hi tony there is another problem.

The Hyperlink must be in this format:javascript:BwGoToVerse('Jdg%2013:1')

With the macro the Hyperlink is in this format:javascript:BwGoToVerse('[Jdg%2013:1]')

The square bracket must be deleted. It is possible?

thanks pasquale

TonyJollans
08-16-2005, 09:47 AM
When I said it was a complete guess I was just being modest ...

It was, of course, an incisive piece of reasoning :rotlaugh:

TonyJollans
08-16-2005, 09:51 AM
Sorry, missed that ..

Try changing ..

Address:="javascript:BwGoToVerse('" & Selection.Range.Text & "')"
to

Address:="javascript:BwGoToVerse('" & Mid$(Selection.Range.Text,2,Len(Selection.Range.Text)-2) & "')"

Pasquale
08-16-2005, 10:06 AM
Hi Tony,

Macro work wonderful. You are a great expert of word-macro.

It is possible automate another find and replace first to launch the macro?
Examples:
My doc has [AAA ##0,##0]

with [AAA ##0:##0]

In original doc there is the comma beetwen the number and j first to launch the macro Hyperlink, execute find comma and replace with colon.

Thanks

TonyJollans
08-16-2005, 10:14 AM
You don't need to do a separate find and replace.

If I understand correctly, try this ..


Sub Macro1()

Selection.HomeKey wdStory

Selection.Find.ClearFormatting
With Selection.Find
.Text = "\[* [0-9]{1;},[0-9]{1;}\]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With

While Selection.Find.Execute
Selection.Hyperlinks.Add Anchor:=Selection.Range, _
TextToDisplay:=Replace(Selection.Range.Text,",",":"), _
Address:="javascript:BwGoToVerse('" & replace(Mid$(Selection.Range.Text,2,Len(Selection.Range.Text)-2),",",":") & "')"
Wend

End Sub

(hope I've got the commas and semicolons correct :)

I have edited this so if you picked the code up real quick and it's not quite right, double check you have the same as (now) posted.

Pasquale
08-16-2005, 10:21 AM
Hi Tony

practically perfect.

Pasquale

TonyJollans
08-16-2005, 10:49 AM
This is Mary Poppins signing off :D