Forum Discussion
coltartjmcsa3
Feb 07, 2022Copper Contributor
Excel VBA and OneDrive SaveCopyAs
I am running office 365 home on windows 10 both latest versions. I have a project that requires the workbook ("Diddly.xlsm") data to be archived every 6 months to a code generated file name leaving t...
- Feb 09, 2022I don't know what the current value of lcFile is when the error occurs?
If you pass just a file name (no path) to the SaveAs method, Excel assumes it needs to be saved in the active directory. Judging by the error message you showed that seems to be c:\Windows. Users are not allowed to save files there. You must provide the SaveAs method with both the path and a filename.
coltartjmcsa3
Feb 09, 2022Copper Contributor
re my msg 9/2/22 I attached the wrong .gif file. Correct file attached. I'm not dong too well with this problem. You probaby noticed I managed to send a msg to myself. Thanks for your patience.
JKPieterse
Feb 09, 2022Silver Contributor
In your code the filename is never assigned, lcFile is an empty string.
- coltartjmcsa3Feb 09, 2022Copper Contributor
I can't apologise enough. This will be my third try at sending you the correct info. The code works when opening the Excel on my laptop when it has access to the resident file locations. When I open Excel from the online view of OneDrive the code fails with the message shown in the attached .gif. I don't see a way round this and I may have to be satisfied by making the archive file "manually" using the Save As option resident in Excel. As I sometimes reply on others to operate the workbook I would have preferred coding. Perhaps I need to find another route to a solution.
- JKPieterseFeb 09, 2022Silver ContributorI don't know what the current value of lcFile is when the error occurs?
If you pass just a file name (no path) to the SaveAs method, Excel assumes it needs to be saved in the active directory. Judging by the error message you showed that seems to be c:\Windows. Users are not allowed to save files there. You must provide the SaveAs method with both the path and a filename.- coltartjmcsa3Feb 09, 2022Copper Contributor
Yes I understand all that. The problem is that the sharer would have to provide the path (we could agree one in advance) and then move the file into OneDrive "manually" (can't see a way to provide a path to OneDrive). As I said earlier I need to find another way round this.
I appreciate your help and have gained some more knowledge on the way.
This is my first time of posting on this site so don't know how to close this out.