VBA will not auto backup file if file lives in Sharepoint

ReignEternal

New Member
Joined
Apr 11, 2021
Messages
30
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a module that is set to backup my excel file when I open the excel document. The issue I have just encountered is if the file lives in a Microsoft Sharepoint location, the VBA errors out. If the file lives on my local network, it works just fine. In the code below, the text in bold is what is in error when the file lives in Sharepoint. The overall endgoal is to have this module work for my local network as well as if it lives in Sharepoint.

Thank you.

VBA Code:
Private Sub Workbook_Open()
    
    Dim FolderPath As String, FileExt As String
    Dim FullFileName As String, msg As String
    Dim Response As VbMsgBoxResult
    Dim FileName As Variant
    
    With ActiveWorkbook
    If .Path = "" Then Exit Sub
    FolderPath = ActiveWorkbook.Path & "\z -Old"
    FileName = Split(ActiveWorkbook.Name, ".")
    FileExt = FileName(1)
    End With
    
    FullFileName = FolderPath & "\" & _
                   FileName(0) & "_" & Format(Now, "mmddyyyy-hhmmss") & "." & FileName(1)
                   
    msg = "The folder or path " & vbNewLine & vbNewLine & _
            FolderPath & vbNewLine & vbNewLine & _
            "does not exist." & vbNewLine & vbNewLine & _
            "Want to create the backup folder?"
                
    
'check if Backup folder already exists
[B]    If Dir(FolderPath, vbDirectory) = vbNullString Then[/B]
'if not ask user to create folder
    Response = MsgBox(msg, 36, "Folder Not Found")
         If Response = vbYes Then MkDir FolderPath Else Exit Sub
    End If
    ActiveWorkbook.SaveCopyAs FileName:=FullFileName
    MsgBox "Auto backup created", 48, "Backup"
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

JEC

Well-known Member
Joined
Aug 21, 2021
Messages
808
Office Version
  1. 365
Platform
  1. Windows
Dir is not able to access sharepoint.
Best way is syncing your sharepoint folders to your explorer. There is a sync button at the sharepoint page. Try to sync the highest parent folder.
Afterwards you can access every file like you used to do.
 

ReignEternal

New Member
Joined
Apr 11, 2021
Messages
30
Office Version
  1. 365
Platform
  1. Windows
Dir is not able to access sharepoint.
Best way is syncing your sharepoint folders to your explorer. There is a sync button at the sharepoint page. Try to sync the highest parent folder.
Afterwards you can access every file like you used to do.
Sadly I get the same error. Looks like I flew too close to the sun on this one. But at least I now now Dir can't access Sharepoint. Thank you.
 

ReignEternal

New Member
Joined
Apr 11, 2021
Messages
30
Office Version
  1. 365
Platform
  1. Windows
Dir is not able to access sharepoint.
Best way is syncing your sharepoint folders to your explorer. There is a sync button at the sharepoint page. Try to sync the highest parent folder.
Afterwards you can access every file like you used to do.
I found a resolution. Follow me on this one. If I place the file on my local network, then I create a shortcut of said file and place that shortcut into Sharepoint, the file creates a backup as intended. However it creates the backup on the local network and not in sharepoint which I and my team are okay with.

Just thought I would share.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,571
Messages
5,770,920
Members
425,652
Latest member
Pemby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top