禁止“正在使用的文件"对话 [英] Suppress 'File In Use' Dialogue

查看:69
本文介绍了禁止“正在使用的文件"对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个程序,它遍历 SharePoint 服务器上的大量 .xlsx 文件,并将每个文件中的数据聚合到一个主文件中.

I have written a procedure which loops through a large number of .xlsx files on a SharePoint server and aggregates data from each into a master file.

我的问题是,在任何给定时间,单个文件可能会被其他用户检出以进行编辑,从而产生以下消息:

My problem is that at any given time, the individual files may be checked out for editing by another user, producing this message:

我需要一个 VBA 解决方案来使用默认的查看只读副本"选项,并取消选中在服务器文件可用时接收通知"选项.

I need a VBA solution to use the default "View a read-only copy" option, and UNCHECK the "Receive a notification when the server file is available" option.

推荐答案

使用 Workbooks.Open 方法 应该让你知道你可以在没有通知的情况下打开只读实例.

Using some of the standard options in the Workbooks.Open method should get you to the point wherw you can open a read-only instance without notification.

Sub open_wbro()
    Dim wb As Workbook, fn As String

    fn = "c:\temp\myWorkbook.xlsx"

    on error goto bm_WB_Open_Error
    Set wb = Workbooks.Open(FileName:=fn, ReadOnly:=True, _
                            IgnoreReadOnlyRecommended:=True, _
                            Notify:=False)
    goto bm_Exit

bm_WB_Open_Error:
    If CBool(Err.Number) Then
        Debug.Print Err.Number & " - " & Err.Description
        Err.Clear
    End If

bm_Exit:
    wb.Close
    Set wb = Nothing
End Sub

这篇关于禁止“正在使用的文件"对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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