• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Replace file

Mr.Karr

Member
Hello

Can anyone please help provide a code snippet or alter the below code for a requirement.

In detail: Below code copies a particular tab and uploads/save as in a sharepoint folder. But can I replace the existing file if with the same file name?

Say now I'm trying to save a file name called "Australia" but if there is already a file name called "Australia", that should replace this.

Code:
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim wb As Workbook
Set wb = Workbooks.Add
ThisWorkbook.Sheets("Reporting").Copy Before:=wb.Sheets(1)

Dim fname          As String
    Dim FPath          As String
    'Dim FName1          As String
   
 
    FPath = "https://microsoft.sharepoint.com/NewFolder/"
    fname = Sheets("Reporting").Range("A18").Text
 
    wb.SaveAs Filename:=FPath & "\" & fname



wb.Save
wb.Close

Application.ScreenUpdating = True
Application.DisplayAlerts = True

Please help.

Many thanks in advance.
 
I'm not had as much practice with SharePoint, but if this was a regular file, you could do:
Code:
Application.DisplayAlerts = False
wb.SaveAs Filename:=FPath & "\" & fname
Application.DisplayAlerts = True
Does that work?
 
Back
Top