jasonfish11
Board Regular
- Joined
- May 14, 2015
- Messages
- 56
Hi all,
I've searched the internet trying to find a way to delete a file from a sharepoint site. I am struggling to make what I've found work, and honestly it's probably because I don't quite understand the coding and have something slightly off.
Essentially what I'm trying to do is "move" a file to a different folder when a checkbox in that file is changed (checkbox is assigned to cell G3). I understand I can't move a file that's open, but I figured I could save a new file then since the new file would be the active one, I could go back and delete the old file.
I am able to make all of this work when the file is not on SharePoint by using the coding of "Kill OldFile" but after extensive search online I've realized that doesn't work in SharePoint and I've tried various "solutions" that I've found to no success. Hopefully you all can point me in the right direction.
Here is what I have...
Everything works except the red text, and I'll be perfectly honest I pulled this from online and am not 100% certain what some of the coding means (like the "Microsoft.xmlhttp" and "Delete". I feel like I should have something else in those areas and that the poster expected someone to update those fields. I just don't know what they should be updated to.
Lastly I've confirmed "OldFile" does show the correct path and name of the file I'm trying to delete.
Any help is welcomed.
Thanks in advance.
I've searched the internet trying to find a way to delete a file from a sharepoint site. I am struggling to make what I've found work, and honestly it's probably because I don't quite understand the coding and have something slightly off.
Essentially what I'm trying to do is "move" a file to a different folder when a checkbox in that file is changed (checkbox is assigned to cell G3). I understand I can't move a file that's open, but I figured I could save a new file then since the new file would be the active one, I could go back and delete the old file.
I am able to make all of this work when the file is not on SharePoint by using the coding of "Kill OldFile" but after extensive search online I've realized that doesn't work in SharePoint and I've tried various "solutions" that I've found to no success. Hopefully you all can point me in the right direction.
Here is what I have...
Code:
Dim Filname As String Dim FilPath As String
Dim NewFilPath As String
Dim OldFile As String
Dim LobjXML As Object
Filname = Sheets("Dashboard").Range("B12").Value & " " & Sheets("Dashboard").Range("B11").Value
FilPath = ActiveWorkbook.Path
OldFile = FilPath & "/" & Filname & ".xlsm"
If FilPath = "http://teams/sites/CREW/AssociateMovementExcel/Sensitive" And Sheets("Dashboard").Range("G3") = False Then
NewFilPath = Sheets("File Path").Range("B3").Value & Filname & ".xlsm"
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=NewFilPath, FileFormat:=52
[COLOR=#ff0000] Set LobjXML = CreateObject("Microsoft.xmlhttp")[/COLOR]
[COLOR=#ff0000] LobjXML.Open "Delete", OldFile, False[/COLOR]
[COLOR=#ff0000] LobjXML.Send[/COLOR]
[COLOR=#ff0000] Set LobjXML = Nothing[/COLOR]
Application.DisplayAlerts = True
End If
Everything works except the red text, and I'll be perfectly honest I pulled this from online and am not 100% certain what some of the coding means (like the "Microsoft.xmlhttp" and "Delete". I feel like I should have something else in those areas and that the poster expected someone to update those fields. I just don't know what they should be updated to.
Lastly I've confirmed "OldFile" does show the correct path and name of the file I'm trying to delete.
Any help is welcomed.
Thanks in advance.
Last edited: