Page 1 of 2 12 LastLast
Results 1 to 40 of 68

Thread: Macro using Excel and Outlook/Exchange

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Macro using Excel and Outlook/Exchange

    Good day everyone. I am looking to build a Macro based out of Outlook and it needs to do the following:
    1) Send out an email with an attachment of a file that will be located in a shared drive. It will be a PDF most of the time but a different name everytime.
    2) It must contain a specific subject line and body
    3) There are about 200 people this email will go out to and they are in about 50 different districts. We want 50 different emails (with multiple email addresses per email) going out per district. All of the user information is listed in an Excel spreadsheet.

    I want to user using this macro to have the least amout of interaction possible. The subject, and body will be static.

    I am fairly new to Macros and would really like some help.

    Thank you.

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    Thank you. Ultimately I would like to automate all of this using a macro button or something of the sort.

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    I am fairly new to Macros and would really like some help.
    Then this is the place I would suggest you to start with.... (See under 'Outlook')

    http://www.vbforums.com/showpost.php...53&postcount=2
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    This was no help. I need help with the code to do this. I am very new to VB code and how to construct something that would work. Any further help would be appreciated.

    Quote Originally Posted by koolsid View Post
    Then this is the place I would suggest you to start with.... (See under 'Outlook')

    http://www.vbforums.com/showpost.php...53&postcount=2

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    This was no help.
    Are you sure?

    1) Send out an email with an attachment of a file that will be located in a shared drive. It will be a PDF most of the time but a different name everytime.
    2) It must contain a specific subject line and body
    The answer to the above two questions lies in the 5th link under Outlook in the FAQ.

    We will come to the 3rd question after you get the above two.

    Let me know if I have misunderstood your query...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    You are correct! The link you pointed me to looks like the correct path for what i want to accomplish. Although I see three different code samples in different languages. It seems like they don't all do the same thing. It seems like the sample in VB 6 would be enough but the attachment wouldn't always be the same name and I would need to pull (#3) my email from the Excel spreadsheet. It should not be one email for all 200 clients. The emails should be split up by Company (which is a column in the Excel spreadsheet) and sent out that way. We would be looking at about 50 emails.

    The whole issue here is that soem clients are having these emails flagged by either their junk mail filter or their company firewall/spam filter. At the moment we add all clients to the BCC list and send it out that way.

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    It seems like the sample in VB 6 would be enough but the attachment wouldn't always be the same name
    I understand that. That is just an FAQ on how you should be approaching your quest. Now If the files are on shared drive, my next question would be... How do I retrieve them? Do I use a Dialog box? or do I have the name of the files stored in a file?

    I can give you the exact code on how to accomplish what you want but then the purpose of this forum would be defeated.

    Mig1980, I would suggest that you take the first code (vb6), understand it, amend it to suit your needs, create a sample code and test it. And yes if you get stuck then post the code that you tried and then yes, we will definitely help you This way you will also learn... This is the way most of us learnt...

    As far as getting different emails are concerned, that is not important for the moment. We will tackle that later. Use a dummy email if you want to for the time being...

    Remember, I will be glad to help you till the time you get what you are looking for... provided you help yourself...
    Last edited by Siddharth Rout; Feb 9th, 2010 at 01:28 PM. Reason: typo
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    Thank you very much. Just one question for the time being, if I wanted a a dialog box to retrieve an attachment how would that be done?

  10. #10
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    Quote Originally Posted by mig1980 View Post
    Thank you very much. Just one question for the time being, if I wanted a a dialog box to retrieve an attachment how would that be done?
    Search the forum on Application.GetOpenFilename
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    OK so, I have worked with the sample code a bit and I got it to work correctly for the most part. I have been trying to get the Application.GetOpenFilename to prompt me with a browsing window to select the file I need to attach. I have not been successful with this part. I even broke it into a function but I have not been successful. Here is the code:

    Code:
    Option Explicit
    'Add a reference to MS Outlook xx.0 Object Library
    Private Sub Command1_Click()
        Dim oApp As Outlook.Application
        Dim oEmail As Outlook.MailItem
        Set oApp = New Outlook.Application
        Set oEmail = oApp.CreateItem(olMailItem)
        With oEmail
            .To = "vette_red1998@yahoo.com"
            .CC = "miguelg@sscal.com"
            .Subject = "(SF)2 Weekly Update"
            .BodyFormat = olFormatRichText
            .HTMLBody = "Good afternoon (SF)&#178; Members,<br><br>Please find attached this week's Update.<br><br>Thank you,<br>Miguel"
            .ReadReceiptRequested = True
            Call OpenFile
            .Attachments.Add OpenFile(), olByValue
            .Recipients.ResolveAll
            .Save
            .Display 'Show the email message and allow for editing before sending
            '.Send 'You can automatically send the email without displaying it.
        End With
        Set oEmail = Nothing
    End Sub
    
    Private Function OpenFile() As String
    
    Dim NewFN As String
    
        NewFN = Application.GetOpenFilename(FileFilter:="PDF File (*.pdf), *.pdf", Title:="Please select a file")
    If NewFN = False Then
         ' They pressed Cancel
         
         MsgBox "Stopping because you did not select a file"
         
        Exit Function
         
    Else
         
       Application.Open FileName:=NewFN
         
    End If
    OpenFile = NewFN
    
    End Function

  12. #12

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    any further help anyone?

  13. #13
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    Will have a look at it tonight
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  14. #14

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    Thank you. Let me know your thoughts. I will continue work on it today.

  15. #15
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    I haven't tested it... just made few quick adjustments in your code....

    See if it works. if it doesn't then tell me the error message that you are getting. I will also test it later in the night...

    Code:
    Option Explicit
    
    Dim AttachFile As String, NewFN As String, boolExit As Boolean
    
    Private Sub Command11_Click()
        Dim oApp As Outlook.Application, oEmail As Outlook.MailItem
        
        Set oApp = New Outlook.Application
        Set oEmail = oApp.CreateItem(olMailItem)
        
        OpenFile
        
        If boolExit = True Then
            msgobx "Please select an attachment"
            Exit Sub
        End If
        
        With oEmail
            .To = "vette_red1998@yahoo.com"
            .CC = "miguelg@sscal.com"
            .Subject = "(SF)2 Weekly Update"
            .BodyFormat = olFormatRichText
            .HTMLBody = "Good afternoon (SF)&#178; Members,<br><br>Please find attached this week's Update.<br><br>Thank you,<br>Miguel"
            .ReadReceiptRequested = True
            
            .Attachments.Add AttachFile, olByValue
            .Recipients.ResolveAll
            .Save
            .Display 'Show the email message and allow for editing before sending
            '.Send 'You can automatically send the email without displaying it.
        End With
        Set oEmail = Nothing
    End Sub
    
    Private Sub OpenFile()
        NewFN = Application.GetOpenFilename(FileFilter:="PDF File (*.pdf), *.pdf", Title:="Please select a file")
        On Error Resume Next
        If NewFN = False Then
            'Pressed Cancel
            MsgBox "Stopping because you did not select a file"
            boolExit = True
            Exit Sub
        Else
            AttachFile = NewFN
        End If
        On Error GoTo 0
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  16. #16

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    Thank you for the updated code. I get a similar error to what I got when I ran my code. It stops on the Application.GetOpenFilename section with an error stating: "Run-time error '438': Object doesn't support this property or method"

  17. #17
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    Ah I got it...

    Outlook doesn't support .GetOpenFilename. Only Excel, Word and PPoint does it... Let me give you an alternative.

    Ok Click on Menu Tools~~> References and select the "Microsoft Common Dialog Control 6.0". If you cannot see it then click on "Browse" and go to the windows system directory and select the comdlg32.ocx file.

    Now in the toolbox, you should see the control. if you don't then right clcik on the toolbox and select the "Additional Controls" option. Then scroll down and select the "Microsoft Common Dialog Control 6.0" Simply add it to your form.

    Use this code in lieu of OpenFile()

    Code:
    Private Sub OpenFile()
        CommonDialog1.DialogTitle = "Select the File..."
        CommonDialog1.Flags = cdlOFNFileMustExist
        CommonDialog1.Filter = "PDF File  (*.pdf)*.pdf"
        CommonDialog1.ShowOpen
    
        If Len(CommonDialog1.FileName) <> 0 Then
            AttachFile = CommonDialog1.FileName
        Else
            MsgBox "Stopping because you did not select a file"
            boolExit = True
        End If
    End Sub
    Last edited by Siddharth Rout; Feb 10th, 2010 at 12:33 PM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  18. #18

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    That makes sense. Thank you.

  19. #19

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    I am getting an invalid qualifier compiling error from the CommonDialog1. I checked the Refrences and I can see the Microsoft Common Dialog Control 6.0 (SP3) checked and it is in the third place from top to bottom of checked items.
    Last edited by mig1980; Feb 10th, 2010 at 01:03 PM. Reason: Updated error

  20. #20

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    any more help here?

  21. #21
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    I just tried it and it works...

    Can you show me the complete code that you are trying and also highlight the line where you are getting the error...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  22. #22

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    Hereb is the code, and the bold area is what gets highlisted saying "Compile Error: Variable not Defined":

    Code:
    Option Explicit
    
    Dim AttachFile As String, boolExit As Boolean
    
    Private Sub Command11_Click()
        Dim oApp As Outlook.Application, oEmail As Outlook.MailItem
        
        Set oApp = New Outlook.Application
        Set oEmail = oApp.CreateItem(olMailItem)
        
        OpenFile
        
        If boolExit = True Then
            MsgBox "Please select an attachment"
            Exit Sub
        End If
        
        With oEmail
            .To = "vette_red1998@yahoo.com"
            .CC = "miguelg@sscal.com"
            .Subject = "(SF)2 Weekly Update"
            .BodyFormat = olFormatRichText
            .HTMLBody = "Good afternoon (SF)&#178; Members,<br><br>Please find attached this week's Update.<br><br>Thank you,<br>Miguel"
            .ReadReceiptRequested = True
            
            .Attachments.Add AttachFile, olByValue
            .Recipients.ResolveAll
            .Save
            .Display 'Show the email message and allow for editing before sending
            '.Send 'You can automatically send the email without displaying it.
        End With
        Set oEmail = Nothing
    End Sub
    
    Private Sub OpenFile()
        CommonDialog1.DialogTitle = "Select the File..."
        CommonDialog1.Flags = cdlOFNFileMustExist
        CommonDialog1.Filter = "PDF File  (*.pdf)*.pdf"
        CommonDialog1.ShowOpen
    
        If Len(CommonDialog1.FileName) <> 0 Then
            AttachFile = CommonDialog1.FileName
        Else
            MsgBox "Stopping because you did not select a file"
            boolExit = True
        End If
    End Sub

  23. #23
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    Did you add the commondialog control on the userform? And If yes, then did you rename it to something else?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  24. #24

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    Not sure I understand where the userform is. I am very new to VB coding. I have all coding added to the section marked "ThisOutlookSession" and the project is called VbaProject.OTM. The code I pasted is all I have.

  25. #25
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    ok, let me attach a snapshot. give me 15 mins
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  26. #26

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    Thank you. I truly appreciate the help.

  27. #27
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    Ok, Let's go to basics now

    Add a userform as shown in the picture. Then Add 1 Textbox, 3 Commandbuttons and 1 CommonDialog control.

    Once done, let me know. We will take it from there...
    Attached Images Attached Images  
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  28. #28

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    I get a prompt saying "Invalid Argument" when I try to add the Common Dialog box.

  29. #29
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    Show me a screenshot...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  30. #30

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    I just registered the .ocx file and now it says "The control could not be created because it is not properly licensed. Just and FYI, I am running Windows Vista 64bit and Office 2003 SP3. Here is a screen shot


  31. #31
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    I am running Windows Vista 64bit and Office 2003 SP3.
    Ah!!!

    What edition of MS Office are you using? I am using the Professional edition.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  32. #32

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    I am also using Office Professional 2003.


  33. #33
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    Ok, leave this with me. It's already 1:55 AM in the morning and I am hitting the sack. i will have a look at it later in the day today....

    Don't worry, we will get this sorted
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  34. #34

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    Thank you very much and have a good night.

  35. #35
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    Ok Try this...

    If you are the administrator of that machine then open an elevated Command Prompt by clicking Start, click All Programs, click Accessories, right-click Command Prompt, and then click Run as administrator.

    Type the following command

    Code:
    regsvr32  &#37;Systemroot%\System32\comdlg32.ocx
    If the dll is successfully registered then you will get the following message...

    DllRegisterServer in C:\WINDOWS\System32\comdlg32.ocx succeeded.
    Let me know if you see this message or not... we will take it from there....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  36. #36

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    I had already tried registering the ocx file and I did it again. Here is what I saw. By the way I continue to get the error stating that the control could not be created because it is not properly licensed when I try to add the "CommonDialog" control to the UserForm.


  37. #37
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    Ok... Forget the commondialog.... Leave everything.... We are going to use a wicked way now....

    Set a reference to Microsoft Excel Object Library from the Tools~~> Reference menu

    and then use this code...

    Code:
    Option Explicit
    
    Dim AttachFile As String, NewFN As String, boolExit As Boolean
    
    Private Sub Command11_Click()
        Dim oApp As Outlook.Application, oEmail As Outlook.MailItem
        
        Set oApp = New Outlook.Application
        Set oEmail = oApp.CreateItem(olMailItem)
        
        OpenFile
        
        If boolExit = True Then
            msgobx "Please select an attachment"
            Exit Sub
        End If
        
        With oEmail
            .To = "vette_red1998@yahoo.com"
            .CC = "miguelg@sscal.com"
            .Subject = "(SF)2 Weekly Update"
            .BodyFormat = olFormatRichText
            .HTMLBody = "Good afternoon (SF)² Members,<br><br>Please find attached this week's Update.<br><br>Thank you,<br>Miguel"
            .ReadReceiptRequested = True
            
            .Attachments.Add AttachFile, olByValue
            .Recipients.ResolveAll
            .Save
            .Display 'Show the email message and allow for editing before sending
            '.Send 'You can automatically send the email without displaying it.
        End With
        Set oEmail = Nothing
    End Sub
    
    
    Private Sub OpenFile()
        Dim xlApp As New Excel.Application
        Dim Filterr As String, Caption As String, SelectedFile As String
        
        xlApp.Visible = False
        Filterr = "PDF files (*.pdf),*.pdf"
        Caption = "Please Select a File "
        SelectedFile = xlApp.GetOpenFilename(Filterr, , Caption)
        xlApp.Quit
        Set xlApp = Nothing
    
        If Len(SelectedFile) <> 0 Then
            AttachFile = SelectedFile
        ElseIf SelectedFile = False Then
            MsgBox "Stopping because you did not select a file"
            boolExit = True
        End If
    End Sub
    Last edited by Siddharth Rout; Feb 11th, 2010 at 01:17 PM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  38. #38

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    I receive the following error and I don't see the variable or a few others defined anywhere.


  39. #39
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro using Excel and Outlook/Exchange

    Add this line

    Code:
    Dim Filterr as String, Caption as String
    after

    Code:
    Dim xlApp As New Excel.Application
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  40. #40

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    38

    Re: Macro using Excel and Outlook/Exchange

    OK, a few more that are not defined: TheUser, and SelectedFile. Are they both String?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width