VB6.0如何判断excel文件是否已打开?
发布网友
发布时间:2022-10-13 02:58
我来回答
共5个回答
热心网友
时间:2023-10-27 22:21
Q1
在打开工作薄之前,可以用这个方法来查看工作薄是否打
on error resume next
set wk=xlapp.workbooks("test")
if err then xlapp.workbooks.open("d\test.xls")
on error goto 0
Q2
第二个问题,可用SAVEAS方法,关键是构建一个新文件名,并且这个文件名在当前目录并不存在,下面代码仅供参考,可以变化很大
k=1
curpath="d:\"
do
if dir("test"). & K & ".xls")<>"" then
.......saveas
exit do
k=K+1
loop
热心网友
时间:2023-10-27 22:22
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
这三句的AS后面都加NEW关键字
不支持推荐的on error resume next
on error resume next是不负责任地一种用法
简直是掩耳盗铃,自欺欺人追问可有更好的方法?谢谢
追答这方法不够好?
热心网友
时间:2023-10-27 22:22
测试 WorkBook 是否已开启
Sub IsWorkBookOpen()
Dim wBook As Workbook
On Error Resume Next
Set wBook = Workbooks("test.xls")
If wBook Is Nothing Then
MsgBox "Workbook is not open"
Set wBook = Nothing
On Error GoTo 0
Else
MsgBox "Yes it is open"
Set wBook = Nothing
On Error GoTo 0
End If
End Sub
热心网友
时间:2023-10-27 22:23
Private Sub Command1_Click()
FileName = "c:\dh.xls"
On Error GoTo err
Name "c:\dh.xls" As "c:\dh2.xls"
Name "c:\dh2.xls" As "c:\dh.xls"
'代码
Exit Sub
err:
MsgBox "文件已经打开"
End Sub
热心网友
时间:2023-10-27 22:23
围观打酱油