+ Reply to Thread
Results 1 to 14 of 14

Adding data from user form to email

Hybrid View

  1. #1
    Registered User
    Join Date
    03-12-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    30

    Adding data from user form to email

    Hi there,

    I am trying to get a little more information on how to get this user form to function as I require it.

    I have got to a stage now where I can make the user form send an email, the body of which I am working on getting to function. However I am unsure as to how to attach the details placed in the user form automatically into the email ready to be sent. I have attached a test work book & it's the sim refresh option that I am working on.

    Would it be possible for anyone to assist with how to get the data input automatically?
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    03-12-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    30

    Re: Adding data from user form to email

    Hi all,

    Just to add in the code I think I'm working with that will send the email. I am getting an error

    "Compile error
    Expected end sub"

    Private Sub CommandButton1_Click()
        Sub Mail_workbook_Outlook_1()
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
        Dim SigString As String
        Dim Signature As String
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        strbody = "Hi there," & _
                  "<br><br><b>Tel:</b><br>" & _
                  "Contract:<br>" & _
                  "<br>Could you please refresh this SIM and let me know the results please. If this SIM has been cancelled if you could please forward a reinstatement onto billing." & _
                  ""
    
        SigString = Environ("appdata") & _
                    "C:\Users\rcranny\AppData\Roaming\Microsoft\Signatures\RESOLVE_Signature.htm"
    
        If Dir(SigString) <> "" Then
            Signature = GetBoiler(SigString)
        Else
            Signature = ""
        End If
    
        On Error Resume Next
    
        With OutMail
            .To = "[email protected]"
            .CC = ""
            .BCC = ""
            .Subject = "ADT RESOLVE SIM CARD REFRESH"
            .HTMLBody = strbody & "<br>" & Signature
            .Send    'or use .Display
        End With
    
        On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
        Unload Me
        End Sub
        End Sub
        
    
    
    Function GetBoiler(ByVal sFile As String) As String
    '**** Kusleika
        Dim fso As Object
        Dim ts As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
        GetBoiler = ts.readall
        ts.Close
    End Function
    In the email body where you can see "Tel" and "Contract" these are the data I would like input from the form.

    Form functions as expected now, just the code that's having issues

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: Adding data from user form to email

    You have two lines of end sub in code. Remove one
    End Sub
    End Sub
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    03-12-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    30

    Re: Adding data from user form to email

    Private Sub CommandButton1_Click()
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
        Dim SigString As String
        Dim Signature As String
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        strbody = "<p style='font-family:calibri;font-size:11pt'>Hi there,</p>" & _
                  "<p style='font-family:calibri;font-size:11pt'><b>Tel:<br>Contract:</b></p>" & _
                  "<p style='font-family:calibri;font-size:11pt'><br>Could you please refresh this SIM and let me know the results please. If this SIM has been cancelled if you could please forward a reinstatement onto billing.</p>" & _
                  "& Signature"
    
        SigString = Environ("appdata") & _
                    "Users\rcranny\AppData\Roaming\Microsoft\Signatures\RESOLVE_Signature.htm"
    
        On Error Resume Next
    
        With OutMail
            .To = "[email protected]"
            .CC = ""
            .BCC = ""
            .Subject = "SIM CARD TEST"
            .HTMLBody = strbody & "<br>" & Signature
            .Display    'or use .Display
        End With
    
        On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
        Unload Me
        End Sub
    Function GetBoiler(ByVal sFile As String) As String
    '**** Kusleika
        Dim fso As Object
        Dim ts As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
        GetBoiler = ts.readall
        ts.Close
    End Function
    Updated now, this is getting an email through as expected and is formatted correctly. However I cannot get the signature section to work.

    Nor do I know how to input the data from my form onto the email. Any help?

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: Adding data from user form to email

    Are you referring to The textbox values on Userform named SIMrefresh.
    Is the signature path correct?
    Should this part
    Signature.htm
    not be
    Signature.html

  6. #6
    Registered User
    Join Date
    03-12-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    30

    Re: Adding data from user form to email

    Yeah the text boxes on the userform I need to input the details next to the corresponding part in the body

    ---

    Nope, neither work. The file is a HTM file as it's a Outlook signature.

    Checked file path and all ok

    Filepath taken from web browser when viewing the signature
    C:\Users\rcranny\AppData\Roaming\Microsoft\Signatures\RESOLVE_Signature.htm


    This is how the email is coming through currently (which is the right format and layout)

    Hi there,
    Tel:
    Contract:

    Could you please refresh this SIM and let me know the results please. If this SIM has been cancelled if you could please forward a reinstatement onto billing.
    & Signature
    Last edited by echoz; 04-04-2017 at 09:11 AM.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,530

    Re: Adding data from user form to email

    Like this maybe.
    Change the red text to the correct userform object names.

    Private Sub CommandButton1_Click()
    
        Dim strbody As String
        Dim SigString As String
        Dim Signature As String
    
        strbody = "<p style='font-family:calibri;font-size:11pt'>Hi there,</p>" & _
                  "<p style='font-family:calibri;font-size:11pt'><b>Tel: " & Texbox1.Text & "<br>Contract: " & textbox2.Text & "</b></p>" & _
                  "<p style='font-family:calibri;font-size:11pt'><br>Could you please refresh this SIM and let me know the results please. If this SIM has been cancelled if you could please forward a reinstatement onto billing.</p>" & _
                  "& Signature"
    
        SigString = Environ("appdata") & _
                    "Users\rcranny\AppData\Roaming\Microsoft\Signatures\RESOLVE_Signature.htm"
        
        If Dir(SigString) <> "" Then
            Signature = GetBoiler(SigString)
        Else
            Signature = ""
        End If
        On Error Resume Next
    
        With CreateObject("Outlook.Application").CreateItem(0)
            .To = "[email protected]"
            .CC = ""
            .BCC = ""
            .Subject = "SIM CARD TEST"
            .HTMLBody = strbody & "<br>" & Signature
            .Display    'or use .Display
        End With
    
        On Error GoTo 0
    
        Unload Me
    End Sub
    Last edited by bakerman2; 04-04-2017 at 09:17 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Registered User
    Join Date
    03-12-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    30

    Re: Adding data from user form to email

    This worked perfect thanks!!

    Any ideas as to why the signature isn't working?

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,530

    Re: Adding data from user form to email

    How about this ?

    SigString = Environ("appdata") & "\Microsoft\Signatures\RESOLVE_Signature.htm"

  10. #10
    Registered User
    Join Date
    03-12-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    30

    Re: Adding data from user form to email

    Sadly not literally so close now to having this part of the project done aswell.

    Any other ideas on a way to work this as this code is one I've plucked from google

    Private Sub CommandButton1_Click()
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
        Dim SigString As String
        Dim Signature As String
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        strbody = "<p style='font-family:calibri;font-size:11pt'>Hi there,</p>" & _
                  "<p style='font-family:calibri;font-size:11pt'><b>Tel: </b>" & simNumber.Text & "<br><b>Contract:</b> " & conNumber.Text & "</p>" & _
                  "<p style='font-family:calibri;font-size:11pt'>Could you please refresh this SIM and let me know the results please. If this SIM has been cancelled if you could please forward a reinstatement onto billing.</p>" & _
                  "<br>"
                  
        SigString = Environ("appdata") & "Microsoft\Signatures\RESOLVE_Signature.htm"
                  
        If Dir(SigString) <> "" Then
            Signature = GetBoiler(SigString)
        Else
            Signature = ""
        End If
        
    
    
        On Error Resume Next
    
        With OutMail
            .To = "[email protected]"
            .CC = ""
            .BCC = ""
            .Subject = "SIM CARD TEST"
            .HTMLBody = strbody & vbNewLine & Signature
            .Send    'or use .Display
        End With
    
        On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
        Unload Me
        End Sub
    
    Function GetBoiler(ByVal sFile As String) As String
    '**** Kusleika
        Dim fso As Object
        Dim ts As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
        GetBoiler = ts.readall
        ts.Close
    End Function
    
    Private Sub Label1_Click()
    
    End Sub
    
    Private Sub Label2_Click()
    
    End Sub
    
    Private Sub TextBox1_Change()
    
    End Sub
    
    Private Sub UserForm_Click()
    
    End Sub

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,530

    Re: Adding data from user form to email

    No need for other code as this works just fine.
    Notice the red \ in your string.

    SigString = Environ("appdata") & "\Microsoft\Signatures\RESOLVE_Signature.htm"

  12. #12
    Registered User
    Join Date
    03-12-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    30

    Re: Adding data from user form to email

    God damn file path, literally missing the beginning \

    Thanks a lot for the help bakerman, managed to get it all sorted and working as I want it to be now
    + rep

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,530

    Re: Adding data from user form to email

    Glad we got it sorted out.
    Thanks for rep+.
    If this answers your question please mark the thread as Solved.

  14. #14
    Registered User
    Join Date
    03-12-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    30

    Re: Adding data from user form to email

    Solved! Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. User Form Data Entry Adding a TimeStamp
    By caltman242 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2015, 09:15 AM
  2. [SOLVED] User Form not adding data
    By JO505 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 02-07-2013, 01:21 PM
  3. Adding "All Borders" with a User Form (Similar to Data Form)
    By kgreave1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2012, 01:57 PM
  4. User Form List Boxes and Adding and Deleting Data
    By learning_vba in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2010, 06:23 PM
  5. email a user form?
    By scadaman29325 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-20-2007, 05:02 AM
  6. Adding data to sheet with user form
    By Jay in forum Excel General
    Replies: 1
    Last Post: 06-08-2005, 11:05 AM

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