+ Reply to Thread
Results 1 to 5 of 5

delete Sharepoint excel document with vba

  1. #1
    Forum Contributor
    Join Date
    08-21-2008
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Office 2007
    Posts
    255

    delete Sharepoint excel document with vba

    I need to delete a workbook from a sharepoint shared folder.

    I have had no success using the nromal methods of -

    Please Login or Register  to view this content.
    This is a file i have published, and have permissions to delete manually etc.

    Any ideas ?

    Is there another way (eg. navigate sharepoint webpage with sendkeys to delete maybe)

  2. #2
    Forum Contributor
    Join Date
    08-21-2008
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Office 2007
    Posts
    255

    Re: delete Sharepoint excel document with vba

    Bump ......


    Any ideas people ?

  3. #3
    Registered User
    Join Date
    11-26-2012
    Location
    cleveland, ohio
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: delete Sharepoint excel document with vba

    Private Sub deletesharepointfile()
    'If nobody has the file checked out
    If Workbooks.CanCheckOut("http://FilePath"") = True Then
    Application.DisplayAlerts = False
    'Open the file on the SharePoint server
    Workbooks.Open Filename:="http://FilePath", UpdateLinks:=xlUpdateLinksNever
    If Workbooks("Book1.xls").SharedWorkspace.Connected Then
    'Delete the file on the SharePoint server
    Workbooks("Book1.xls").SharedWorkspace.RemoveDocument
    End If
    'Close the workbook
    Workbooks("Book1.xls").Close
    Application.DisplayAlerts = True
    Else
    Application.DisplayAlerts = False
    'Open the File to check if you already have it checked out
    Workbooks.Open Filename:="http://FilePath", UpdateLinks:=xlUpdateLinksNever
    'See if doc can be checked in
    If Application.Workbooks("Book1.xls").CanCheckIn Then
    'Check In, Save and Close
    Application.Workbooks("Book1.xls").CheckIn SaveChanges:=True, Comments:="Checked-In before Delete"
    'Open the file again
    Workbooks.Open Filename:="http://FilePath"
    If Workbooks("Book1.xls").SharedWorkspace.Connected Then
    'Delete the file on the SharePoint server
    Workbooks("Book1.xls").SharedWorkspace.RemoveDocument
    End If
    'Close the workbook
    Workbooks("Book1.xls").Close
    End If
    End If

  4. #4
    Registered User
    Join Date
    04-17-2020
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    6

    Re: delete Sharepoint excel document with vba

    Stumbled across this code as it's exactly what I'm looking to do, but when I append this code into my macro, the macro executes but "Book1.xls" is not removed from SharePoint. Anything you might suggest I look into as to why the file would not be getting removed?

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: delete Sharepoint excel document with vba

    Quote Originally Posted by ezraNBC View Post
    Stumbled across this code as it's exactly what I'm looking to do, but when I append this code into my macro, the macro executes but "Book1.xls" is not removed from SharePoint. Anything you might suggest I look into as to why the file would not be getting removed?
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1