Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ActiveWorkbook.SaveAs when the template is on OneDrive

ActiveWorkbook.SaveAs when the template is on OneDrive

ActiveWorkbook.SaveAs when the template is on OneDrive

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.


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.


RE: ActiveWorkbook.SaveAs when the template is on OneDrive

Do you really have a folder named "myname" in C:\Users\ location?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: ActiveWorkbook.SaveAs when the template is on OneDrive

I have a folder with a name corresponding to my actual name.
I have obfuscated that in the posted code to protect my identity.

RE: ActiveWorkbook.SaveAs when the template is on OneDrive

In case someone else encounters this, solution is to use the OneDrive form of the path instead of the local form.


MyPath = "C:\Users\myname\OneDrive - My Company\Documents\Expenses\" 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close