VBA 共享工作簿和非共享工作簿
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17457504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Shared workbook and Unshared workbook
提问by Lucas Bertollo
I tried to find the code to share workbook and unshared it with visual basic but I didn't find it, anyone know if its possible?
我试图找到共享工作簿的代码并与visual basic取消共享,但我没有找到它,有人知道它是否可能吗?
Another thing is shared workbooks when saved, update the workbook to all users... the question is if I save it with visual basic code the workbook will update to another users?
另一件事是保存时共享工作簿,将工作簿更新给所有用户......问题是如果我用visual basic代码保存它,工作簿将更新给其他用户?
I am coding an button that when clicked it (share the workbook > fill the cells > save and unshared it).
我正在编写一个按钮,单击它时(共享工作簿 > 填充单元格 > 保存并取消共享)。
回答by Andy G
I certainly agree with pnuts and the link he provided: Shared Workbooks are horrible.
我当然同意 pnuts 和他提供的链接:共享工作簿太可怕了。
To respond to the question though, if you record a macro in Excel you will see code like the following when you share a workbook.
不过,要回答这个问题,如果您在 Excel 中录制宏,您将在共享工作簿时看到如下代码。
Sub Macro1()
Workbooks.Add
With ActiveWorkbook
.KeepChangeHistory = True
.ChangeHistoryDuration = 30
End With
ActiveWorkbook.SaveAs Filename:= _
"F:\Documents and Settings\student\My Documents\Book1.xlsx", FileFormat:= _
xlOpenXMLWorkbook, AccessMode:=xlShared
ActiveWorkbook.ExclusiveAccess
End Sub
(If you don't already know how to record a macro in Excel then I recommend that you take the time to find out - it is extremely useful, particularly when you are just starting with VBA.)
(如果您还不知道如何在 Excel 中录制宏,那么我建议您花点时间了解一下 - 这非常有用,尤其是当您刚开始使用 VBA 时。)
If you copy this code into the VB Editor and click on certain words (SaveAs
in particular) and press F1 you will get into the Help system.
如果您将此代码复制到 VB 编辑器并单击某些词(SaveAs
特别是)并按 F1,您将进入帮助系统。
From this recorded macro I surmise that removing Shared from a workbook is just a case of using SaveAs
with an AccessMode
other than xlShared
(or omitted). After all, this is the dialog/option that appears when we manually share or un-share a workbook.
从这个录制的宏中,我推测从工作簿中删除 Shared 只是SaveAs
与AccessMode
其他xlShared
(或省略)一起使用的情况。毕竟,这是我们手动共享或取消共享工作簿时出现的对话框/选项。
But, to emphasize, I am not advocating the use of Shared Workbooks.
但是,要强调的是,我并不提倡使用共享工作簿。