简体   繁体   English

使用VBA从Excel工作表中的列表中打开文件夹

[英]Open folder from list in Excel sheet using VBA

This code is used to open a specific folder. 此代码用于打开特定的文件夹。

Dim strFolderPath As String 
strFolderPath = “C:\temp\” 
ThisWorkbook.FollowHyperlink (strFolderPath)

I need to open a folder saved in an Excel sheet (like in the image below). 我需要打开一个保存在Excel工作表中的文件夹(如下图所示)。 I need to read the path in Excel and to open the folder. 我需要在Excel中读取路径并打开文件夹。

Let's say you have your table in the first three columns from A to C. You can write your serial number in cell E1 and run macro. 假设您在A到C的前三列中都有表格。您可以在单元格E1中写入序列号并运行宏。 For example, if you enter 3 in cell E1 and click the button, the folder from Edres will be open. 例如,如果您在单元格E1中输入3并单击按钮,则来自Edres的文件夹将打开。

Dim strFolderPath As String
Dim NrRow As Long
NrRow = Cells(1, 5)
strFolderPath = Cells(NrRow + 1, 3).Value
ThisWorkbook.FollowHyperlink (strFolderPath)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM