请教VB高手一个excel的问题

来源:百度知道 编辑:UC知道 时间:2024/06/07 11:27:49
我向excel表格中输入一些数,如这个excel文件没打开,程序运行时就输入进去了;如打开的话,它就会问:这个表格已存在,是否保存副本?怎么能让它不问而直接输入进去呢?

首先判断文件是否打开,没有打开时再打开。
Private Function IsOpen(ByVal sFile As String) As Boolean
Dim fFile As Integer
Dim Msg As String
fFile = FreeFile()
On Error GoTo ErrOpen
Open sFile For Binary Lock Read Write As fFile
Close fFile
Exit Function
ErrOpen:
If Err.Number <> 70 Then
'Msg = "Error # " & str(Err.Number) & " was generated by " & Err.source & Chr(13) & Err.Description
'MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
IsOpen = False
Else
IsOpen = True
End If
End Function