As suggested by the MVPS site I put my hyperlinks in macrobutton fields to be
able to get an event whenever the user clicks it. This is done
programmatically from an addin written in VB 6 and works fine. The only
problem is when the inserted hyperlink is too long. I then get the text
"DisplayText cannot span
more than one line!" and I understand this, but is there a way to detect the
condition either by testing the length before or detecting the error after it
has happened? I need to be able to tell my user what to do about it.

Re: Can I detect when a MacroButton text would span more than one line by Klaus

Klaus
Mon May 02 20:47:33 CDT 2005

Hi Anna,

When you create the hyperlink, perhaps you can truncate the actual =
address in the .TextToDisplay ... say if the address is longer than a =
certain number of characters?

Klaus=20



"Anna Neiderud" <AnnaNeiderud@discussions.microsoft.com> wrote:
> As suggested by the MVPS site I put my hyperlinks in macrobutton =
fields to be=20
> able to get an event whenever the user clicks it. This is done=20
> programmatically from an addin written in VB 6 and works fine. The =
only=20
> problem is when the inserted hyperlink is too long. I then get the =
text=20
> "DisplayText cannot span=20
> more than one line!" and I understand this, but is there a way to =
detect the=20
> condition either by testing the length before or detecting the error =
after it=20
> has happened? I need to be able to tell my user what to do about it.

Re: Can I detect when a MacroButton text would span more than one by AnnaNeiderud

AnnaNeiderud
Tue May 03 01:00:02 CDT 2005

Thanks for your suggestion, but how would I know what number of characters to
use? I need to be sure, and since characters have varying width, and
different font sizes can be used, I cannot set a fixed number.

/Anna

"Klaus Linke" wrote:

> Hi Anna,
>
> When you create the hyperlink, perhaps you can truncate the actual address in the .TextToDisplay ... say if the address is longer than a certain number of characters?
>
> Klaus
>
>
>
> "Anna Neiderud" <AnnaNeiderud@discussions.microsoft.com> wrote:
> > As suggested by the MVPS site I put my hyperlinks in macrobutton fields to be
> > able to get an event whenever the user clicks it. This is done
> > programmatically from an addin written in VB 6 and works fine. The only
> > problem is when the inserted hyperlink is too long. I then get the text
> > "DisplayText cannot span
> > more than one line!" and I understand this, but is there a way to detect the
> > condition either by testing the length before or detecting the error after it
> > has happened? I need to be able to tell my user what to do about it.
>

Re: Can I detect when a MacroButton text would span more than one by Klaus

Klaus
Tue May 03 05:03:17 CDT 2005

If your page (or column) width isn't really small, wouldn't some =
guesstimate like 40 or 50 characters work?
If you want to exploit the full available space, or that space varies =
wildly because of different column widths or font sizes, you could =
probably add an error handler to the macro that inserts the hyperlink, =
and truncate the .TextToDisplay in the error handler (then reinsert the =
hyperlink) until the error disappears.
Seems like a lot of work though, which I'd probably avoid if possible =
;-)

Regards,
Klaus


"Anna Neiderud" wrote:
> Thanks for your suggestion, but how would I know what number of=20
> characters to use? I need to be sure, and since characters have =
varying=20
> width, and different font sizes can be used, I cannot set a fixed =
number.
>=20
> /Anna
>=20
> "Klaus Linke" wrote:
>=20
> > Hi Anna,
> >=20
> > When you create the hyperlink, perhaps you can truncate the actual=20
> > address in the .TextToDisplay ... say if the address is longer than =
a=20
> > certain number of characters?
> >=20
> > Klaus=20
> >=20
> >=20
> >=20
> > "Anna Neiderud" <AnnaNeiderud@discussions.microsoft.com> wrote:
> > > As suggested by the MVPS site I put my hyperlinks in macrobutton =
fields to be=20
> > > able to get an event whenever the user clicks it. This is done=20
> > > programmatically from an addin written in VB 6 and works fine. The =
only=20
> > > problem is when the inserted hyperlink is too long. I then get the =
text=20
> > > "DisplayText cannot span=20
> > > more than one line!" and I understand this, but is there a way to =
detect the=20
> > > condition either by testing the length before or detecting the =
error after it=20
> > > has happened? I need to be able to tell my user what to do about =
it.
> >

Re: Can I detect when a MacroButton text would span more than one by AnnaNeiderud

AnnaNeiderud
Tue May 03 05:55:07 CDT 2005

The second approach with the errorhandler sounds like what I'm looking for,
unfortunately I don't seem to get an error. The only indication of the error
that I can see is the text displayed in the document and I can't see that
programmatically.

/Anna

"Klaus Linke" wrote:

> If your page (or column) width isn't really small, wouldn't some guesstimate like 40 or 50 characters work?
> If you want to exploit the full available space, or that space varies wildly because of different column widths or font sizes, you could probably add an error handler to the macro that inserts the hyperlink, and truncate the .TextToDisplay in the error handler (then reinsert the hyperlink) until the error disappears.
> Seems like a lot of work though, which I'd probably avoid if possible ;-)
>
> Regards,
> Klaus
>
>
> "Anna Neiderud" wrote:
> > Thanks for your suggestion, but how would I know what number of
> > characters to use? I need to be sure, and since characters have varying
> > width, and different font sizes can be used, I cannot set a fixed number.
> >
> > /Anna
> >
> > "Klaus Linke" wrote:
> >
> > > Hi Anna,
> > >
> > > When you create the hyperlink, perhaps you can truncate the actual
> > > address in the .TextToDisplay ... say if the address is longer than a
> > > certain number of characters?
> > >
> > > Klaus
> > >
> > >
> > >
> > > "Anna Neiderud" <AnnaNeiderud@discussions.microsoft.com> wrote:
> > > > As suggested by the MVPS site I put my hyperlinks in macrobutton fields to be
> > > > able to get an event whenever the user clicks it. This is done
> > > > programmatically from an addin written in VB 6 and works fine. The only
> > > > problem is when the inserted hyperlink is too long. I then get the text
> > > > "DisplayText cannot span
> > > > more than one line!" and I understand this, but is there a way to detect the
> > > > condition either by testing the length before or detecting the error after it
> > > > has happened? I need to be able to tell my user what to do about it.
> > >
>

Re: Can I detect when a MacroButton text would span more than one by Jean-Guy

Jean-Guy
Tue May 03 09:18:54 CDT 2005

Anna Neiderud was telling us:
Anna Neiderud nous racontait que :

> The second approach with the errorhandler sounds like what I'm
> looking for, unfortunately I don't seem to get an error. The only
> indication of the error that I can see is the text displayed in the
> document and I can't see that programmatically.

Just a quick thought here...
What if you put the Fields(1).Result in a string? Won't that string hold the
error code if the text is too long? ("DisplayText cannot span more than one
line!")

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org




Re: Can I detect when a MacroButton text would span more than one by Klaus

Klaus
Tue May 03 09:55:56 CDT 2005

Hi Jean-Guy,

> What if you put the Fields(1).Result in a string? Won't that=20
> string hold the error code if the text is too long? ("DisplayText=20
> cannot span more than one line!")

It should, but it doesn't seem to :-(

Hi Anna,

Should have tried...
You use something like { MacroButton mymacro { Hyperlink =
"http://www.some.org" }}, right?

Regards,
Klaus


> Anna Neiderud was telling us:
> Anna Neiderud nous racontait que :
>=20
> > The second approach with the errorhandler sounds like what I'm
> > looking for, unfortunately I don't seem to get an error. The only
> > indication of the error that I can see is the text displayed in the
> > document and I can't see that programmatically.
>=20

"Jean-Guy Marcil" <no-spam@leaveme.alone> wrote:
> Just a quick thought here...
> What if you put the Fields(1).Result in a string? Won't that string =
hold the=20
> error code if the text is too long? ("DisplayText cannot span more =
than one=20
> line!")
>=20
> --=20
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
>=20
>=20
>

Re: Can I detect when a MacroButton text would span more than one line by Jonathan

Jonathan
Tue May 03 10:24:23 CDT 2005


"Anna Neiderud" <AnnaNeiderud@discussions.microsoft.com> wrote in message
news:C6E07CAB-9AE6-4449-8C21-31B8BA887C1E@microsoft.com...
> As suggested by the MVPS site I put my hyperlinks in macrobutton fields to
> be
> able to get an event whenever the user clicks it. This is done
> programmatically from an addin written in VB 6 and works fine. The only
> problem is when the inserted hyperlink is too long. I then get the text
> "DisplayText cannot span
> more than one line!" and I understand this, but is there a way to detect
> the
> condition either by testing the length before or detecting the error after
> it
> has happened? I need to be able to tell my user what to do about it.

Hi Anna

If the text to be converted into a macrobutton field is currently selected,
then you can check whether the selection wraps to the next line like this

If Selection.End > ActiveDocument.Bookmarks("\Line").Range.End Then
'Selection is too long
Else
'Selection is ok
End If


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org


Re: Can I detect when a MacroButton text would span more than one by AnnaNeiderud

AnnaNeiderud
Wed May 04 01:55:02 CDT 2005

> You use something like { MacroButton mymacro { Hyperlink
"http://www.some.org" }}, right?

Yes, thats what I am using, and the hyperlink is inserted using
rng.Hyperlinks.Add(rng, url) rather than using TextToDisplay (since it needs
to contain symbols in some cases). Therefore Jonathan West's suggestion below
sounds promissing. I'll try that.

Thanks for the discussion.

/Anna

Re: Can I detect when a MacroButton text would span more than one by AnnaNeiderud

AnnaNeiderud
Wed May 04 03:18:49 CDT 2005

Thanks!

It didn't make the code look nice (since I didn't have the text selected and
had to select it and than select the old selection again) but it works :-)

/Anna

"Jonathan West" wrote:

>
> "Anna Neiderud" <AnnaNeiderud@discussions.microsoft.com> wrote in message
> news:C6E07CAB-9AE6-4449-8C21-31B8BA887C1E@microsoft.com...
> > As suggested by the MVPS site I put my hyperlinks in macrobutton fields to
> > be
> > able to get an event whenever the user clicks it. This is done
> > programmatically from an addin written in VB 6 and works fine. The only
> > problem is when the inserted hyperlink is too long. I then get the text
> > "DisplayText cannot span
> > more than one line!" and I understand this, but is there a way to detect
> > the
> > condition either by testing the length before or detecting the error after
> > it
> > has happened? I need to be able to tell my user what to do about it.
>
> Hi Anna
>
> If the text to be converted into a macrobutton field is currently selected,
> then you can check whether the selection wraps to the next line like this
>
> If Selection.End > ActiveDocument.Bookmarks("\Line").Range.End Then
> 'Selection is too long
> Else
> 'Selection is ok
> End If
>
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
>
>

Re: Can I detect when a MacroButton text would span more than one by AnnaNeiderud

AnnaNeiderud
Wed May 04 03:32:10 CDT 2005

And if someone else will be using this technique I need to add that you need
to put the text first on a line first, then do the check, and then move it
back as desired. Otherwise you might get undesired results since a hyperlink
in running text can wrap also when it is not as long as a line and then it
would still work in a macrobutton field.

Here is some code in case someone wants it (perhaps overly complex for
general use, but due to the rest of my application I need it to look this
way):

' insertionRange contains the text in question and is part of
' the range macroButtonField.Code i.e. { macrobutton macro <insertionRange> }
Private Sub InsertLinkInMacroButtonField(insertionRange As Range,
macroButtonField As Field, address As String)
Dim oldSelection As Range
Dim hl As Word.Hyperlink
Dim hlRange As Range
Dim rng As Range
Dim rngToRemove As Range
Set oldSelection = Selection.Range.Duplicate

' Cut and paste insertion Range to a new fresh line, check if it is
wrapping and
' if so truncate and copy back
Set rng = GetFieldRange(macroButtonField)
rng.Collapse wdCollapseStart
rng.insertBefore vbCr & vbCr
Set rngToRemove = rng.Duplicate
rng.Collapse wdCollapseStart
rng.MoveStart wdCharacter, 1
insertionRange.Cut
rng.Paste

rng.Select
Dim truncated As Boolean
Dim rngToTruncate As Range
truncated = False
While Selection.End > evDoc.Bookmarks("\Line").Range.End And
Len(rng.text) >= 1
'Selection is too long
Set rngToTruncate = rng.Duplicate
rngToTruncate.Start = rngToTruncate.End - 1
rngToTruncate.text = ""
truncated = True
Wend
If truncated And (Len(rng.text) >= 3) Then
Set rngToTruncate = rng.Duplicate
rngToTruncate.Start = rngToTruncate.End - 3
rngToTruncate.text = "..."
rng.End = rngToTruncate.End
End If

' cut and paste rng back, insert hyperlink, remove extra characters at
range
rng.Cut
insertionRange.Paste
rngToRemove.text = ""
insertionRange.Hyperlinks.Add insertionRange, address

oldSelection.Select
end sub

Public Function GetFieldRange(f As Field) As Range
Dim rng As Range
Set rng = f.Code.Duplicate
rng.TextRetrievalMode.IncludeFieldCodes = True
rng.TextRetrievalMode.IncludeHiddenText = True
rng.Start = rng.Start - 1
rng.End = rng.End + 1
Set GetFieldRange = rng
End Function


"Anna Neiderud" wrote:

> Thanks!
>
> It didn't make the code look nice (since I didn't have the text selected and
> had to select it and than select the old selection again) but it works :-)
>
> /Anna
>
> "Jonathan West" wrote:
>
> >
> > "Anna Neiderud" <AnnaNeiderud@discussions.microsoft.com> wrote in message
> > news:C6E07CAB-9AE6-4449-8C21-31B8BA887C1E@microsoft.com...
> > > As suggested by the MVPS site I put my hyperlinks in macrobutton fields to
> > > be
> > > able to get an event whenever the user clicks it. This is done
> > > programmatically from an addin written in VB 6 and works fine. The only
> > > problem is when the inserted hyperlink is too long. I then get the text
> > > "DisplayText cannot span
> > > more than one line!" and I understand this, but is there a way to detect
> > > the
> > > condition either by testing the length before or detecting the error after
> > > it
> > > has happened? I need to be able to tell my user what to do about it.
> >
> > Hi Anna
> >
> > If the text to be converted into a macrobutton field is currently selected,
> > then you can check whether the selection wraps to the next line like this
> >
> > If Selection.End > ActiveDocument.Bookmarks("\Line").Range.End Then
> > 'Selection is too long
> > Else
> > 'Selection is ok
> > End If
> >
> >
> > --
> > Regards
> > Jonathan West - Word MVP
> > www.intelligentdocuments.co.uk
> > Please reply to the newsgroup
> > Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
> >
> >