Excel VBA错误1004 Can';“找不到”;“文件名”;尝试打开文件时
我正在尝试打开指定文件夹中的所有Excel文件(.xlsx),并从每个文件中提取信息,以添加到报表的主电子表格中 我无法打开文件。我得到一份工作 运行时错误“1004” 说找不到FILE.xlsx 文件名正确,并且与文件名和扩展名(.xlsx)匹配 代码的最后一行不起作用Excel VBA错误1004 Can';“找不到”;“文件名”;尝试打开文件时,excel,vba,Excel,Vba,我正在尝试打开指定文件夹中的所有Excel文件(.xlsx),并从每个文件中提取信息,以添加到报表的主电子表格中 我无法打开文件。我得到一份工作 运行时错误“1004” 说找不到FILE.xlsx 文件名正确,并且与文件名和扩展名(.xlsx)匹配 代码的最后一行不起作用 Dim FileName As String Dim Folder As String Dim Month As String Dim File As Variant Month = MonthName(CurrentMon
Dim FileName As String
Dim Folder As String
Dim Month As String
Dim File As Variant
Month = MonthName(CurrentMonth)
Folder = "C:\Users\mpresley\Documents\Other\Ben\Forecast Summary\Forecast"
FolderName = Folder & Month & CurrentYear
Dim firstEmptyRow As Long
Dim attachmentFolder As String, StrFile As String, filenameCriteria As String
Dim attachmentWorkBook As Workbook
Dim copyRngToArray As Variant
'# Set file extension
filenameCriteria = "xlsx"
'set
StrFile = Dir(FolderName & "\*" & filenameCriteria)
Do While Len(StrFile) > 0
Set attachmentWorkBook = Workbooks.Open(StrFile)
指定文件夹路径和文件名:
Set attachmentWorkBook = Workbooks.Open(FolderName & "\" & StrFile)
文件夹名称中缺少路径分隔符,文件扩展名中缺少“.”