如何从特定文件夹中打开Excel

时间:2014-11-27 15:10:52

标签: excel excel-vba vba

例如:我有一个名为TEST的文件夹名称。并且TEST包含aaa.xlsx,bbb.xlsx,ccc.xlsx,.......,zzz.xlsx 现在,如果我在单元格中输入文件名(aaa.xlsx)并输入vba按钮,它应该显示来自aaa.xlsx的数据。

-Folder名称和文件名是静态的。

2 个答案:

答案 0 :(得分:0)

尝试此操作添加单个工作簿:

Sub openworksheet()
Workbooks.Open Filename:="C:\Users\........\test.xlsx" 'past your file path within " "
End Sub

答案 1 :(得分:0)

创建的文件名列表是sheet1。

Sub DropDown2_Change()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
ThisWorkbook.Activate
Sheets("dropdown").Select
Range("a5:Z1000").Clear
    With Worksheets("dropdown").Shapes("Drop Down 2").ControlFormat
    'MsgBox "ListIndex: " & .ListIndex & vbNewLine & "List value:" & .List(.ListIndex)
    Sheets("dropdown").Range("A3").Value = .List(.ListIndex)
    End With
    currentfile = Sheets("dropdown").Range("a3").Value
Workbooks.Open Filename:=ThisWorkbook.Path & "\path\" & currentfile
ActiveSheet.UsedRange.Select
Selection.Copy
ThisWorkbook.Activate
Sheets("Dropdown").Activate
ActiveSheet.Range("a5").Select
ActiveSheet.Paste
Windows(currentfile).Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub