Excel 2013 - 根据2个不同单元格中的数据打开网络位置

时间:2015-11-04 16:02:38

标签: excel-vba vba excel

我想使用2个单元格中的组合数据,然后在我的网络上搜索该特定文件夹。

结构如下:

  • B栏:公司名称
  • C栏:部件号

组合路径类似于:

\\ds2\data\customer\customer docs\${COMPANY_NAME}\${PART_NUMBER}

预期结果是Windows资源管理器视图,其中包含具有该部件号的所有文件夹。

有关示例,请参阅following image

1 个答案:

答案 0 :(得分:0)

这不会打开资源管理器,但会为您提供可以在该文件夹中找到的匹配目录的可点击链接列表

'this assumes there is a sheet named "Results" with a header in row 1
'output is a list of links on the results page matching that part
Sub GetFileList()
Const BaseFilePath As String = "C:\Test\" '"\ds2\data\customer\customer docs\"
Sheets("Results").Rows("2:100000").Clear
FilePath = BaseFilePath & Sheets("Search").Cells(1, 1) & "\" 'cells(1,1) has the company, adjust as necessary
FileSearch = "*" & Sheets("Search").Cells(1, 2) & "*" 'cells(1,2) has the part, adjust as necessary
r = 2
folderresult = Dir(FilePath & FileSearch, vbDirectory)
While folderresult <> ""
    Sheets("Results").Cells(r, 1) = FilePath & folderresult
    Sheets("Results").Hyperlinks.Add Anchor:=Sheets("Results").Cells(r, 1), Address:= _
        FilePath & folderresult, TextToDisplay:=FilePath & folderresult
    folderresult = Dir$
    r = r + 1
Wend
End Sub