I have a simple macro enabled excel template (.xltm) that prompts for a file name and saves the file in the desired location when a new file is created.
This has always worked fine. Until now.
The error occurs on the ActiveWorkbook.SaveAs line.
The error given is: "Microsoft Excel cannot access the file 'C:\Users\myname\Documents\Expenses\CE895A'"
Although the file name changes each time.
Recently we have transitioned to using OneDrive as our backup. So now the template resides in a local drive folder that is synchronized to OneDrive.
It seems to me that the file that can't be accessed must be a temp file related to OneDrive.
When entering Debug the variables "MyPath" and "FileName" are as expected - correctly pointing to a local drive folder.
Given that nothing is "wrong" with the code, I'm at a loss about how to debug further to resolve this.
Suggestions?
Code:
Sub SetMyName()
Dim FileName As String
Dim MyPath As String
If Sheets("Expense Report").Range("J41").Value = 0 Then 'only if no paid amount
FileName = InputBox("Expense Purpose and File Name")
If Len(FileName) > 0 Then
Range("B13").Value = FileName
MyPath = "C:\Users\myname\Documents\Expenses\"
ActiveWorkbook.SaveAs MyPath & FileName & ".xlsm", xlOpenXMLWorkbookMacroEnabled
End If
End If
End Sub
This has always worked fine. Until now.
The error occurs on the ActiveWorkbook.SaveAs line.
The error given is: "Microsoft Excel cannot access the file 'C:\Users\myname\Documents\Expenses\CE895A'"
Although the file name changes each time.
Recently we have transitioned to using OneDrive as our backup. So now the template resides in a local drive folder that is synchronized to OneDrive.
It seems to me that the file that can't be accessed must be a temp file related to OneDrive.
When entering Debug the variables "MyPath" and "FileName" are as expected - correctly pointing to a local drive folder.
Given that nothing is "wrong" with the code, I'm at a loss about how to debug further to resolve this.
Suggestions?