简体   繁体   English

错误 1004:SaveAs 方法失败,accessMode:=xlShared

[英]Error 1004: SaveAs Method Failed, accessMode:=xlShared

I have a problem with a macro.我有一个宏的问题。

Sub ActivePartage()

Dim Destwb As Workbook
Dim TempFile As String
Dim FileExtStr As String
Dim FileFormat As Integer
Set Destwb = ActiveWorkbook

strTestString = Left(Destwb.Name, (InStrRev(Destwb.Name, ".", -1, vbTextCompare) - 1))

FileExtStr = ".xlsm": FileFormatNum = 52
TempFile = "H:\DQM\Tableau de Bord DQM\" & strTestString

Application.DisplayAlerts = False
With Destwb
    .SaveAs TempFile & FileExtStr, FileFormat:=FileFormatNum, AccessMode:=xlShared
End With
Application.DisplayAlerts = True

End Sub

I tried to figure it out why there is an error (filenamen format...etc) I know it's working without AccessMode:=xlShared , but I need to save it as shared mode.我试图弄清楚为什么会出现错误(文件名格式......等)我知道它在没有AccessMode:=xlShared的情况下工作,但我需要将它保存为共享模式。 I am using Excel 2016, my code has been inspired from this link :我正在使用 Excel 2016,我的代码受到此链接的启发:

Could someone help me please?有人可以帮我吗?

I believe this might be caused because to save a files as shared you first needs to have exclusive access to it.我相信这可能是因为要将文件保存为共享文件,您首先需要对其具有独占访问权限。

try opening it in exclusive then save as shared.尝试以独占方式打开它,然后另存为共享。

With Destwb
    .ExclusiveAccess
    .SaveAs TempFile & FileExtStr, FileFormat:=FileFormatNum, AccessMode:=xlShared

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM