Results 1 to 5 of 5

Automating Excel Through Outlook HEEELP

Threaded View

  1. #1
    Registered User
    Join Date
    05-24-2014
    Posts
    6

    Automating Excel Through Outlook HEEELP

    Hey guys, I'm new to the forum, my name is Jassie.

    So I've been given some very redundant reporting tasks, and I know I can automate them so I don't have to spend hours every month doing them. unfortunately, I just started learning VBA about 2 weeks a go. I can definitely help people with some SQL Server stuff!

    Basically, I want to flag specific emails based on the subject, email address. Then save it, open it up in Excel and call a macro to do some formatting so it can be uploaded into a database. After all that is done, save it and email it back to the sender... But I can't seem to get outlook to do anything...

    Any help would really be appreciated, here's what I've got so far, hopefully it's just a silly mistake.

    Option Explicit
    
    Private WithEvents olInboxItems As Items
    
    Private Sub Application_Startup()
        Dim objNS As Outlook.NameSpace
        Dim X As Integer
    
        Set objNS = GetNamespace("MAPI")
        Set olInboxItems = Session.GetDefaultFolder(olFolderInbox).Items
    End Sub
    
    Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Dim olMailItem As MailItem
    Dim olAttName As String
    Dim objNS As Outlook.NameSpace
    Dim olDestFldr As Outlook.MAPIFolder
    Dim ExcelApp As Object
    Dim ExcelWK As Object
    Dim Att As String
    Set objNS = GetNamespace("MAPI")
     
        If TypeOf Item Is MailItem Then
            Set olMailItem = Item
     
            
            If olMailItem.Attachments.Count = 1 _
            And olMailItem.SenderEmailAddress = "SENDER'[email protected]" _
           And InStr(olMailItem.Subject, "this is a test of automation") > 0 Then
                    
                Const AttPath As String = "C:\Users\jvaughn\Desktop\Test"
                Set olDestFldr = objNS.Folders("Inbox - *my personal email*").Folders("Inbox").Folders("Test")
     
                Set ExcelApp = CreateObject("Excel.Application")
                      
                Set olAttName = olMailItem.Item(1).FileName
                olMailItem.Attachments.Item(1).SaveAsFile AttPath + olAttName + Date
                
                On Error Resume Next
                            
                ExcelApp.Workbooks.Open (AttPath + olAttName + Date)
                ExcelApp.Run (PERSONAL.XLSB!TestingMacro1)
                    
                ExcelApp.Workbooks.Close
               Kill AttPath & Att
                ExcelApp.Quit
     
                olMailItem.UnRead = False
                olMailItem.Move olDestFldr
            End If
        End If
    End Sub
    Last edited by jassievon; 05-24-2014 at 01:17 PM. Reason: readability

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Automating outlook calendar invitations
    By K G in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-15-2014, 10:00 PM
  2. [SOLVED] Automating the Outlook VBA code.
    By ciapul12 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-05-2014, 08:17 PM
  3. Automating Outlook with Excel
    By mppotter in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-05-2011, 11:16 AM
  4. heeelp!
    By erkamu in forum Excel General
    Replies: 1
    Last Post: 01-20-2011, 01:13 PM
  5. Heeelp!
    By Deadloss in forum Excel General
    Replies: 4
    Last Post: 12-22-2005, 06:31 PM

Tags for this Thread

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