我想通过从对话框中选择一个文件来打开文件并设置工作簿。 选择文件并将文件位置存储在wbCombinedName中可以正常工作。
但是,wbCombined并非总是正确设置。例如。如果我打开并保存了文件,则运行marco它将不起作用。当我重新打开文件时,它确实起作用。当我检查变量wbCombined fullname时,我相信已设置了打开的最新文件的名称。
是否可以调整下面的Set语句,还是应该包括检查以查看要打开的工作簿是否为已打开的工作簿?谢谢
Set FileO = Application.FileDialog(msoFileDialogFilePicker)
With FileO
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode1
wbCombinedName = .SelectedItems(1)
End With
Set wbCombined = Workbooks.Open(Filename:=wbCombinedName, UpdateLinks:=0)
答案 0 :(得分:1)
Function WORKBOOK_OPEN(strWorkbookname As String, _
Optional strCheckPath As String = "") As Boolean
Dim w As Excel.Workbook
For Each w In Workbooks
If w.Name = strWorkbookname Then
WORKBOOK_OPEN = True
If strCheckPath <> "" Then
WORKBOOK_OPEN = w.Path = strCheckPath
End If
End If
Next w
End Function