Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

swith between .xls and Outlook

Status
Not open for further replies.

BobBob10

Programmer
Apr 24, 2005
57
GB
I have this code which opens outlook and displays an email. However, I was wondering how to then switch back to excel from outlook.

Code:
Sub EmailandSaveCellValue(ByVal strRec As String) 
     
     'Variable declaration
    Dim oApp As Object, oMail As Object, WB As Workbook, _ 
    FileName As String, MailSub As String, MailTxt As String 
     
     '*************************************************  ********
     'Set email details; Comment out if not required
    MailTo = strRec 
    MailSub = "Please review the attached Diary Event Dates Report." 
    MailTxt = "This is a Automated Email sent by the user " & Application.UserName 
     '*************************************************  ********
     'Turns off screen updating
     'Application.ScreenUpdating = False
     
     'Makes a copy of the active sheet and save it to
     'a temporary file
    ActiveSheet.Copy 
    Set WB = ActiveWorkbook 
    FileName = ActiveSheet.Name & ".xls" 
    On Error Resume Next 
    Kill "C:\" & FileName 
    On Error Goto 0 
    WB.SaveAs FileName:="C:\" & FileName 
     
     'Creates and shows the outlook mail item
    Set oApp = CreateObject("Outlook.Application") 
    Set oMail = oApp.CreateItem(0) 
    With oMail 
        .To = MailTo 
        .CC = MailCC 
        .BCC = MailBCC 
        .Subject = MailSub 
        .Body = MailTxt 
        .Attachments.Add WB.FullName 
        .Display 
    End With 
     
     'oMail.Send
     
     'Deletes the temporary file
    WB.ChangeFileAccess Mode:=xlReadOnly 
    Kill WB.FullName 
    WB.Close SaveChanges:=False 
     
     'Restores screen updating and release Outlook
     'Application.ScreenUpdating = True
    Set oMail = Nothing 
    Set oApp = Nothing 
End Sub

Thanks
 
[tt]AppActivate()[/tt]?

You will need to grab the application title of Excel before shifting the focus to Outlook so you can feed that value back into [tt]AppActivate()[/tt].

I am sorry I have not succeeded in answering all of your questions.
In fact, I apologize for not completely answering any of them.
The answers I have however do serve to raise a whole new set of questions I had not previously thought of. In some ways, I am as confused as you are but I believe my confusions are (as always) on a higher plane and
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top