希望你能帮助我理解我在这里做错了什么。
作为我的 Outlook 宏的一部分,我希望使用指向文档的超链接更新 excel 中的单元格。
'~~> Excel variables
Dim oXLApp As Object, oXLwb As Object, oXLws As Object
'~~> Establish an EXCEL application object
On Error Resume Next
Set oXLApp = GetObject(, "Excel.Application")
'~~> If not found then create new instance
If Err.Number <> 0 Then
Set oXLApp = CreateObject("Excel.Application")
End If
Err.Clear
On Error GoTo 0
'~~> Show Excel
oXLApp.Visible = True
'~~> Open the relevant file
Set oXLwb = oXLApp.Workbooks.Open("V:Dirfilename.xls")
'~~> Set the relevant output sheet. Change as applicable
Set oXLws = oXLwb.Sheets("Outstanding")
oXLws.Range("R11").Select
oXLws.Range("R11").Hyperlinks.Add Anchor:=Selection, Address:= _
"V:Dir" & emailsub & ".msg" _
, TextToDisplay:="Here"
出于某种原因,它只是调试,代码在 excel 中工作正常,所以我一定错过了一些东西,请帮忙!
干杯,多姆
由于您是后期与 Excel 绑定的,Outlook 不明白什么是Selection
更改这些行
oXLws.Range("R11").Select
oXLws.Range("R11").Hyperlinks.Add Anchor:=Selection, Address:= _
"V:Dir" & emailsub & ".msg", TextToDisplay:="Here"
自
oXLws.Range("R11").Hyperlinks.Add Anchor:=oXLws.Range("R11"), Address:= _
"V:Dir" & emailsub & ".msg", TextToDisplay:="Here"