[Solved] AOO Basic string with embedded quotes
Posted: Sat Nov 18, 2017 7:59 pm
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.
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
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 & ")"
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