简体   繁体   中英

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. 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

RunTime Error 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. I also tried adding more attributes - both to file opening and saving methods, like readonly:=false, ignorereadonlyrecommendation:=true, file format:=xlworbookdefault etc, no effect. 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..

Any help is appreciated, this tool is key to my daily work and so far upgrading to new excel made everything worse:[

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:

ActiveWorkbook.LockServerFile

I never used that before while on Excel 2010, didn't even know it existed up until now

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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