简体   繁体   English

VBA 移动到 Office 365 后的 SaveAs 问题

[英]VBA issue with SaveAs after moving to Office 365

I'm experiencing problems with my macro that was written under Excel 2010 after moving to Office 365. In short - I've got a macro stored in a central file stored in a sharedrive that opens several files from different SharePoint folders, pastes some data in each and saves.迁移到 Office 365 后,我在 Excel 2010 下编写的宏遇到问题。简而言之 - 我有一个宏存储在一个存储在共享驱动器中的中央文件中,该文件从不同的 SharePoint 文件夹打开多个文件,粘贴一些数据在每个和保存。 To do that I use:为此,我使用:

Set WB = Workbooks.Open (filename:=path, UpdateLinks:=0)
[some code]
WB.SaveAs Filename=:path

This was perfectly fine under excel 2010, now I get这在 excel 2010 下非常好,现在我明白了

RunTime Error 1004.运行时错误 1004。

Also, when I stop the macro completely after it crashes on the SaveAs method, and try to do the saving manually - entire excel crashes immediately and restarts.. I tried googling differences between the excel generations in that context but I found nothing.此外,当我在 SaveAs 方法崩溃后完全停止宏并尝试手动保存时 - 整个 excel 立即崩溃并重新启动。我尝试在这种情况下搜索 excel 代之间的差异,但我什么也没找到。 I also tried adding more attributes - both to file opening and saving methods, like readonly:=false, ignorereadonlyrecommendation:=true, file format:=xlworbookdefault etc, no effect.我还尝试添加更多属性 - 文件打开和保存方法,如readonly:=false, ignorereadonlyrecommendation:=true, file format:=xlworbookdefault等,没有效果。 I also noticed, that when macro crashes, the file that was supposed to be saved and closed is in ReadOnly despite including readonly:=false in the Workbooks.open method - as if this was completely ignored..我还注意到,当宏崩溃时,尽管在Workbooks.open方法中包含readonly:=false ,但应该保存和关闭的文件仍处于ReadOnly中 - 就好像这被完全忽略了一样。

Any help is appreciated, this tool is key to my daily work and so far upgrading to new excel made everything worse:[感谢任何帮助,这个工具是我日常工作的关键,到目前为止升级到新的 excel 让一切变得更糟:[

Ok, I found the answer - apparently it was related to opening files from server (the Sharepoint piece) and due to that a new line of code is necessary which is:好的,我找到了答案 - 显然它与从服务器打开文件(Sharepoint 部分)有关,因此需要一行新代码,即:

ActiveWorkbook.LockServerFile

I never used that before while on Excel 2010, didn't even know it existed up until now我以前在 Excel 2010 上从未使用过它,直到现在才知道它存在

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

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