Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Delete save as file

Posted on 2010-11-10
6
Medium Priority
?
329 Views
Last Modified: 2012-05-10
Hi Experts,

I would like to request Experts help. How to delete the save as workbook at “ActiveWorkbook.SaveAs ThisWorkbook.path” after the document is delivered via email? Hope Experts could help to add this feature in the attached script.



Function SendMsg(strSubject As String, _
                   strBody As String, _
                   strTO As String, _
                   Optional strDoc As String, _
                   Optional strCC As String, _
                   Optional strBCC As String)
       
    Dim oLapp
    Dim oItem
    Dim myattachments
    Dim fs As String

    Set oLapp = CreateObject("Outlook.Application")
    Set oItem = oLapp.CreateItem(olMailItem)
    Application.DisplayAlerts = False
    ThisWorkbook.Sheets("Request").Copy
    Call deleteButton2
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    ThisWorkbook.VBProject.VBComponents("GMT").Export Environ("Temp") & "\GMT.bas"
    ActiveWorkbook.VBProject.VBComponents.Import (Environ("Temp") & "\GMT.bas")
    
    ActiveWorkbook.SaveAs ThisWorkbook.path & "\" & Sheets("Request").Cells(1, "i") & "_" & Sheets("Request").Cells(5, "I") & ".xls", FileFormat:=-4143
   
    
    Application.DisplayAlerts = True
    fs = ActiveWorkbook.FullName
    ActiveWorkbook.Close

   oItem.Subject = strSubject
     
    

    addr1 = "thv@gmail.com"
   

    oItem.To = addr1 + ";" + addr2 '+ ";" + addr3

    oItem.CC = strCC
   
    oItem.BCC = strBCC
    'oItem.BodyFormat = olFormatHTML
    oItem.htmlbody = strBody
    oItem.Importance = olImportanceHigh
    oItem.attachments.Add fs
'
  
   oItem.display 'send
   
   
   
    Set oLapp = Nothing
    Set oItem = Nothing
       
End Function

Open in new window

0
Comment
Question by:Theva
5 Comments
 
LVL 7

Expert Comment

by:mkobrin
ID: 34109003
I'm not sure about the VB syntax, but the C# Syntax would be:
System.IO.File.Delete(fs);

I'm assuming that the fs string contains the full path and file name of the file you want to delete.

You should put this just before the Set oLapp = nothing command.

regards,

Mike
0
 
LVL 50

Accepted Solution

by:
Dave Brett earned 2000 total points
ID: 34109020
replace

oItem.display 'send

with

Dave

oItem.display 'send
Kill fs

Open in new window

0
 

Expert Comment

by:gladson1976
ID: 34109075

 oItem.display 'send
' Below is the code added in between ur code starts here
'fs.DeleteFile (Server.MapPath("./XXFolder") & "\XXFilename*.*")   ' If required use this to delete all the files

'fs.DeleteFile(FilePath)
fs.DeleteFile("\" & Sheets("Request").Cells(1, "i") & "_" & Sheets("Request").Cells(5, "I") & ".xls")

'Above is the code added in between ur code ends here
  Set oLapp = Nothing
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 34109095
gladson1976

fs is a string. Not the scripting object which is not utilised in this code

Dave
0
 

Author Closing Comment

by:Theva
ID: 34109201
Hi,

Thanks for the help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
A few solutions to a problem some of us have been having when trying to add Hostgator email accounts to Outlook 2016 (will probably work with Outlook 2013 as well).
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question