+ Reply to Thread
Results 1 to 7 of 7

outlook email to textbox variable

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-05-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    209

    outlook email to textbox variable

    Below is my coding and attachment of what I want looks like.
    Private Sub TextBox1_Change()
        Dim strName As String
        Subject = UserForm1.TextBox1 <- I dont think this is correct
    End Sub
    
    Private Sub TextBox2_Change()
        CC = UserForm1.TextBox2 <- I dont think this is correct
    End Sub
    
    Private Sub TextBox3_Change()
        Message = UserForm1.TextBox3 <- I dont think this is correct
    End Sub
    Private Sub CommandButton1_Click()
        Unload Me
    End Sub
    
    Sub CommandButton2_Click()
    Set myOlApp = CreateObject("Outlook.Application")
    Set myNamespace = myOlApp.GetNamespace("MAPI")
            Set objMail = myOlApp.CreateItem(olMailItem)
                With objMail
                    .Subject = Subject <- how do i link this to "I dont think this is correct"
                    .To = Environ("username")
                    .body = Message <- how do i link this to "I dont think this is correct"
                    .CC = CC <- how do i link this to "I dont think this is correct"
                    .Send
    End With
    'below i dont understand why it's there and nothing or if needed
    Set myOlApp = Nothing
    Set myNamespace = Nothing
    Set myRecipient = Nothing
    Set objMail = Nothing
    End Sub
    Attached Images Attached Images
    Last edited by JBeaucaire; 09-10-2012 at 09:39 PM. Reason: Added code tags, as per forum rules. Don't forget!

  2. #2
    Registered User
    Join Date
    08-13-2012
    Location
    Newark, DE
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: outlook email to textbox variable

    Why don't you remove the textbox change events and pull the textbox values into the email fields directly? I also commented out the Send command and added Display, so you can see that it works.

    Private Sub CommandButton1_Click()
        Unload Me
    End Sub
    Sub CommandButton2_Click()
    
    Dim myOlApp As Object
    Dim objMail As Object
            
    Set myOlApp = CreateObject("Outlook.Application")
    Set objMail = myOlApp.CreateItem(olMailItem)
    With objMail
        .Subject = TextBox1
        .To = Environ("username")
        .body = TextBox3
        .CC = TextBox2
        '.Send
        .Display
    End With
    
    'below i dont understand why it's there and nothing or if needed
    Set myOlApp = Nothing
    Set myNamespace = Nothing
    Set myRecipient = Nothing
    Set objMail = Nothing
    
    End Sub
    http://www.mrspreadsheets.com

  3. #3
    Forum Contributor
    Join Date
    09-05-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    209

    Re: outlook email to textbox variable

    Are you saying use .display so it bring up outlook and edit manually? That's not what I want. I don't want outlook to popup at all. My project is I have to have it like the pictures, which in forms.

  4. #4
    Registered User
    Join Date
    08-13-2012
    Location
    Newark, DE
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: outlook email to textbox variable

    No, that's not what I am saying. I was suggesting to use the Display command when testing the code. Once you are happy with how it looks, then you can replace it with Send.

  5. #5
    Forum Contributor
    Join Date
    09-05-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    209

    Re: outlook email to textbox variable

    Good idea, but I still need help connect the text box to the outlook.

  6. #6
    Registered User
    Join Date
    08-13-2012
    Location
    Newark, DE
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: outlook email to textbox variable

    I gave you a way to do that in my first post.

     .Subject = TextBox1
     .body = TextBox3
     .CC = TextBox2

  7. #7
    Forum Contributor
    Join Date
    09-05-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    209

    Re: outlook email to textbox variable

    Gotcha! I didn't know just by that code it automatically grab from textbox, I thought I had to add variables. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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