Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveWorkbook.SaveAs when the template is on OneDrive 1

Status
Not open for further replies.

mintjulep

Technical User
Aug 20, 2004
1,536
0
36
JP
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.

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?
 
Do you really have a folder named "myname" in C:\Users\ location?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
No.
I have a folder with a name corresponding to my actual name.
I have obfuscated that in the posted code to protect my identity.
 
In case someone else encounters this, solution is to use the OneDrive form of the path instead of the local form.

Code:
MyPath = "C:\Users\myname\OneDrive - My Company\Documents\Expenses\"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top