就在几天前,我还可以用部分文件名打开工作簿。
但是今天,我试了几次这个代码,他仍然说1004错误
为什么?
Sub open_data_workbook()
Dim myPath As String
Dim main_workbook As String
Dim data_workbook As String
Dim xlsxm As String
Dim code_name As String
With ActiveSheet
code_name = Range("B" & Cells(Rows.Count, 2).End(xlUp).Row).Value
myPath = ThisWorkbook.Path & "\"
xlsxm = ".xlsx"
data_workbook = "*" & code_name & "*" & xlsxm
main_workbook = "EMS-Part Data.xlsm"
End With
Application.ScreenUpdating = False
Workbooks.Open Filename:=myPath & data_workbook
End Sub发布于 2020-11-01 10:43:55
开放式工作簿
快速修正
Option Explicit
Sub open_data_workbook()
Dim myPath As String
Dim main_workbook As String
Dim data_workbook As String
Dim xlsxm As String
Dim code_name As String
With ActiveSheet
code_name = .Range("B" & .Cells(.Rows.Count, 2).End(xlUp).Row).Value
myPath = ThisWorkbook.Path & "\"
xlsxm = ".xlsx"
data_workbook = Dir("*" & code_name & "*" & xlsxm)
If data_workbook = "" Then
MsgBox "File not found.", vbCritical, "Fail"
Exit Sub
End If
main_workbook = "EMS-Part Data.xlsm"
End With
Application.ScreenUpdating = False
Workbooks.Open Filename:=myPath & data_workbook
End Subhttps://stackoverflow.com/questions/64630520
复制相似问题