2013-10-10 86 views
2

希望你能幫助我理解我在這裏做錯了什麼。Outlook到Excel超鏈接問題

作爲我的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:\Dir\filename.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很好,所以我一定是失去了一些東西,請大家幫幫忙!

乾杯,大教堂

回答

3

既然你用Excel latebinding,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"