Page 1 of 1

[Solved] AOO Basic string with embedded quotes

Posted: Sat Nov 18, 2017 7:59 pm
by edhannahs
Was writing a simple macro to set formulae in cells as hyperlink function but stumbled across a problem with quotes as part of string. With trial and error I found something that works but don't understand the reasoning.

Code: Select all

qt               = """"
hyper            = "=HYPERLINK(" & qt & "#"
Sht2Name         = "Sheet2"
lnk              = hyper & Sht2Name & gt & qt & "; " & qt & Sht2Name & qt & ")"
lnk2             = hyper & Sht2Name & gt      & "; " & qt & Sht2Name & qt & ")"
lnk3             = hyper & "Sheet2" & qt      & "; " & qt & "Sheet2" & qt & ")"
shortlnk         = hyper & Sht2Name                                  & qt & ")"

This produces the following strings:
lnk =HYPERLINK("#Sheet2"; "Sheet2")
lnk2 =HYPERLINK("#Sheet2; "Sheet2")
lnk3 =HYPERLINK("#Sheet2"; "Sheet2")
shortlnk =HYPERLINK("#Sheet2")

lnk2 is not quoted properly (missing " after the first Sheet2) but the others are. I expected lnk2 to be correct but not lnk. I thought lnk2 was equivalent to lnk3. Why does it need the extra qt? shortlnk does not seem to need the extra qt. Just want to understand so I don't stumble around so much next time.

Windows 10

Re: OO Basic string with embedded quotes

Posted: Sat Nov 18, 2017 9:35 pm
by Zizi64
Try to use the code of the qoutes:

Code: Select all

qt = Chr(34)

Re: OO Basic string with embedded quotes

Posted: Sat Nov 18, 2017 9:38 pm
by Zizi64

Code: Select all

hyper & Sht2Name & gt & qt & "; " & qt & Sht2Name & qt & ")"
You have typed

Code: Select all

gt (GT)
instead of

Code: Select all

qt (QT)
in your sample.

Re: OO Basic string with embedded quotes [Solved]

Posted: Sun Nov 19, 2017 7:09 am
by edhannahs
Yes! Argh! Thank you! Stupid typos.