VBA will not auto backup file if file lives in Sharepoint

ReignEternal

New Member
Joined
Apr 11, 2021
Messages
41
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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

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
Back
Top