VBA Save Active workbook Save as file name Error when Microsoft OneDrive is On

Edgarvelez

Board Regular
Joined
Jun 6, 2019
Messages
197
Office Version
  1. 2016
Platform
  1. Windows
Hi all,
I have a code sown below which works and has for years.
We now have Microsoft OneDrive and it doesn't work and I get an error, if I turn off OneDrive it works great.

All the code does it takes one of the sheets copies it, saves & renames it to the same folder the macro is regardless of the folder location.


1653745752231.png


Full Code below

VBA Code:
    Sheets("DATA PAGE").Select
    Range("A1").Select
    Dim fname As String
    Dim fpath As String
    Dim name As String
    Dim ws As Worksheet
        If ActiveWorkbook.AutoSaveOn Then ActiveWorkbook.AutoSaveOn = False
    fpath = ActiveWorkbook.Path
    'ActiveWorkbook.Path
   
    fname = Range("D7") & " " & Range("D8") & " PSO " & Range("'HYD PACKING LIST'!I6") & "-1 " & Range("D10") & ".xlsx"
    name = Range("D7").Value

    On Error Resume Next
    Set ws = ThisWorkbook.Sheets("UPLOAD SHEET")
    On Error GoTo 0

    If ws Is Nothing Then
    MsgBox "sheet doesn't exist"
    Exit Sub
    End If


    If Dir(fpath & "\" & fname) = vbNullString Then
    ThisWorkbook.Sheets("UPLOAD SHEET").Copy
    ActiveWorkbook.SaveAs Filename:=fpath & "\" & fname
    Else
        msg = MsgBox(fname & Chr(10) & Chr(10) & "This File Name Already Exists In The Folder!!" & Chr(10) & Chr(10) & _
    "Click YES to continue to save and overwrite the file" & Chr(10) & _
    "Or NO to to cancel the Save", vbYesNo, "STOP!")
    If msg = vbYes Then
    Application.DisplayAlerts = False
    ThisWorkbook.Sheets("UPLOAD SHEET").Copy
    ActiveWorkbook.SaveAs Filename:=fpath & "\" & fname
    Application.DisplayAlerts = True
    Else
    MsgBox "File save cancelled"
    End If
    End If

End Sub
 

Attachments

  • 1653745662023.png
    1653745662023.png
    56.8 KB · Views: 44

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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