检查excel工作簿是否打开? [英] Check if excel workbook is open?

查看:85
本文介绍了检查excel工作簿是否打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以...我将这段代码用作参考:

So... I used this piece of code for reference:

Option Explicit

Sub Sample()
Dim Ret

Ret = IsWorkBookOpen("C:\myWork.xlsx")

If Ret = True Then
    MsgBox "File is open"
Else
    MsgBox "File is Closed"
End If
End Sub

Function IsWorkBookOpen(FileName As String)
Dim ff As Long, ErrNo As Long

On Error Resume Next
ff = FreeFile()
Open FileName For Input Lock Read As #ff
Close ff
ErrNo = Err
On Error GoTo 0

Select Case ErrNo
Case 0:    IsWorkBookOpen = False
Case 70:   IsWorkBookOpen = True
Case Else: Error ErrNo
End Select
End Function

我用了我的工作簿和所有内容,但在第15行返回了语法错误:ff = FreeFile _().

I used my workbook and everything, but it returns Syntax error on line 15: ff = FreeFile_().

为什么会这样?有什么语法错误?我正在尝试检查其他用户是否打开了工作簿,因为这样的话,我无法将值保存在工作簿中.

Why is this the case? What syntax error is there? I am trying to check if workbook is opened by some other user, because if that's the case, I can't save the values in the Workbook.

谢谢答案,D.

推荐答案

我认为您已经将代码复制/粘贴到了VBA编辑器中.因此,清理代码,删除所有不需要的空白,验证每一行的结束位置.

I think you done copy/paste the code into VBA editor. So clean the code, delete all blancks that are not needed, verify where each line is finished.

这篇关于检查excel工作簿是否打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆