我创建了一个使用for循环打开工作簿列表并将数据从打开的工作簿复制到活动工作簿的代码。
我已经知道了如何复制数据,但是我想为每个工作簿添加一个超链接。每个文件的路径都在strPath字符串中找到。
我要将超链接分配给单元格:
sheet.Cells(index, dateColumn) (请注意,date列只是我找到的列号,这要感谢FindDate函数)。
以下是我到目前为止所拥有的:
For index = 3 To 37 
    dateColumn = FindDate(portfolioDate)
    portfolioName = ActiveSheet.Range("A" & index & "").Value & ".xls"
    strPath = "G:\Risk\Risk Reports\VaR-Stress test\" & portfolioDate & "\" & portfolioName & ""
    Set wb = Workbooks.Open(strPath)     
    sheet.Cells(index, dateColumn).Value = wb.Close Savechanges:=False
Next index发布于 2019-07-23 12:15:44
看来你的语法错了。
请在现场试用以下方法:
Set wb = Workbooks.Open(strPath)     
    sheet.Cells(index, dateColumn).Value = strPath
With sheet 
   .Hyperlinks.Add Anchor:=.Cells(index, dateColumn), _ 
   Address:=strPath, _ 
   ScreenTip:="Path to the file", _ 
   TextToDisplay:="File Path to " & "\" & portfolioName & portfolioDate ' Change strPath as per your Requirement to display a different text
End With
wb.Close Savechanges:=False但我不确定代码中的sheet是否是一个变量。
https://stackoverflow.com/questions/57163860
复制相似问题