vba 新建excel保存在一个固定位置,如果该文件存在,则打开,应该如何编写
2个回答
展开全部
把下面的代码加到你要打开的模块中,就可以了
Sub OpenFile(Filename as string)
if ExistFile(Filename) then
Application.Workbooks.Open (Filename)
end if
End Sub
Function ExistFile(Filename As String) As Boolean
On Error GoTo Err1
Dim strName As String
If Filename = "" Then GoTo Err1
If Dir(Filename) <> "" Then
ExistFile = True
Return
Else
ExistFile = False
End If
Exit Function
Err1:
MsgBox "文件名不能为空"
End Function
Sub OpenFile(Filename as string)
if ExistFile(Filename) then
Application.Workbooks.Open (Filename)
end if
End Sub
Function ExistFile(Filename As String) As Boolean
On Error GoTo Err1
Dim strName As String
If Filename = "" Then GoTo Err1
If Dir(Filename) <> "" Then
ExistFile = True
Return
Else
ExistFile = False
End If
Exit Function
Err1:
MsgBox "文件名不能为空"
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询