我在E栏中显示了我的超链接,如图所示
\\maroon\cgm images\mech.pdf
但我想在单元格中仅显示mech.pdf
如何修改我的代码。
用于显示上述超链接的代码如下所示:
str = "\\maroon\CGM Images\" & pn & ".pdf"
ActiveSheet.Hyperlinks.Add Range("e" & i), str
在此,我只想展示pn
& str
。
答案 0 :(得分:1)
您需要指定TextToDisplay
ActiveSheet.Hyperlinks.Add Anchor:=Range("e" & i), Address:=Str, TextToDisplay:=pn & ".pdf"
有时,Excel VBA reference确实有助于您自行了解函数和方法的工作原理:Hyperlinks.Add Method (Excel)
答案 1 :(得分:-1)
如果你有
\ maroon \ cgm images \ mech.pdf
在一个单元格中,你只想获得带有“.pdf”的pdf名称,你可以做下一个代码:
Dim spliter() as String
Dim str_pdf as String
str = \maroon\cgm images\mech.pdf ' Cells(a,b).value
spliter = Split(str, " ") 'To do the first split (You can delete ', " "' )
spliter = Split(spliter(1), "\")
'Now spliter(1) == mech.pdf so...
str_pdf = spliter(1) ' spliter(0) == images , spliter(1) == mech.pdf