Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

vba - Excel cell hyperlink automatically change from "path" to "url"

I have this procedure to add an (absolute) link to a cell. VBA creates the link fine but Excel automatically changes the previous link to an URL link.

Sub SetHyperlink(ByVal wsSheets_I As Worksheets, ByVal sPDFFile_I As String, ByVal lRowMd_I As Long)
    ActiveSheet.Hyperlinks.Add _
      Anchor:=wsSheets_I.Range("A" & lRowMd_I), _
      Address:=sPDFFile_I, _
      TextToDisplay:=wsSheets_I.Cells("C" & lRowMd_I).Value
End Sub

For example: D:ReportsFile 154867452 of 154867500 files.pdf chage to: ReportsFile%20154867452%20of%20154867500%20files.pdf if I select "Modify hyperlink" in Excel context menu

Then Debug.Print (wsSheets_I.Range("A" & lRowMd_I).Hyperlinks(1).Address)

returns Reports/File 154867452 of 154867500 files.pdf (changing "" to "/") but the link works correctly in Excel.

How can I do that Debug.Print (wsSheets_I.Range("A" & lRowMd_I).Hyperlinks(1).Address) return the original D:ReportsFile 154867452 of 154867500 files.pdf

I don't care about the relative or absolute path (Hyperlink Base property)

Excel 365 MSO (16.0.135302)32 bits, Windows 10 (64 bits)

question from:https://stackoverflow.com/questions/65891413/excel-cell-hyperlink-automatically-change-from-path-to-url

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...