Newbie here. I've created a Macro-enabled word document with a Submit button. The document is read-only, so what I'm trying to do is have it save a temp file, attach the temp file, then delete it. Simple enough, right? Everything works except it won't delete. Attached is the code for the Submit button. Please help! Thanks.
Public Sub SubmitButton_Click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim sTempFilePath As String
Application.ScreenUpdating = False
sTempFilePath = ("C:\temp\test.doc")
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
ActiveDocument.SaveAs FileName:="C:\temp\test.doc"
With EmailItem
.Subject = "Application For Leave Form"
.To = "email@email.com"
.Attachments.Add sTempFilePath
.Send
End With
Application.ScreenUpdating = True
Set OL = Nothing
Set EmailItem = Nothing
Set Doc = Nothing
ActiveDocument.Close
Kill sTempFilePath
End Sub
For simplicity I took out a lot of the code, and it's still not deleting the file. What's wrong with this?
Public Sub SubmitButton_Click()
Dim Doc As Document
Dim sTempFilePath As String
sTempFilePath = ("C:\temp\test.doc")
Set Doc = ActiveDocument
ActiveDocument.SaveAs FileName:="C:\temp\test.doc"
ActiveDocument.Close
Kill sTempFilePath
End Sub