Incorporating a UserForm in place of multiple InputBoxes

ChaosPup

New Member
Joined
Sep 27, 2021
Messages
48
Office Version
  1. 365
Platform
  1. Windows
Back again for more help!
As per title. Current code looks like this -
VBA Code:
Sub XXXX()

'Set variables
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim combody As String
Dim upname As String
Dim EmptyRow As Range
Dim wsLOG As Worksheet: Set wsLOG = Worksheets("LOG")

'Set up comments InputBox
combody = InputBox("Please enter any comments", "Comments")

'Set up initials InputBox
upname = InputBox("Please enter your name", "Updated By")

'Set up Outlook
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

'Create Mail in Outlook
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

strbody = "Hello," & vbNewLine & vbNewLine & _
          "This is a test" & vbNewLine & vbNewLine & _
          "**********THIS EMAIL HAS BEEN AUTOMATICALLY GENERATED, PLEASE DO NOT RESPOND**********"

On Error Resume Next
With OutMail
    .To = "XXXX"
    .CC = ""
    .BCC = ""
    .Subject = "TEST"
    .Body = strbody & vbNewLine & vbNewLine & "COMMENTS - " & combody & vbNewLine & vbNewLine & "UPDATE BY - " & upname
    'You can add a file like this
    '.Attachments.Add ("C:\test.txt")
    .Send 'or use.Display
End With
On Error GoTo 0

'Write details to log
Set EmptyRow = wsLOG.Range("A" & wsLOG.Cells(Rows.Count, "A").End(xlUp).Row + 1).Resize(1, 4)
    EmptyRow.Cells(1).Value2 = combody: EmptyRow.Cells(2).Value2 = Date: EmptyRow.Cells(3).Value2 = Time: EmptyRow.Cells(4).Value2 = upname

Set OutMail = Nothing
Set OutApp = Nothing

MsgBox ActiveCell.Value & vbNewLine & _
"UPDATE SENT"

End Sub

The bit I want to change is this -

InputBox.png

I've created the UserForm -

Userform.png

But I don't know how to actually incorporate it into my current code. Can anyone help?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Move your code to the userform OK button click event. Refer to the userform controls like:

combody = Me.Textbox1 'lousy name for a userform control but that's my guess as to what you have
You probably should use validation code to ensure something has been entered into your controls. Even better if you can ensure they are valid entries.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Incorporating a Userform instead of multiple InputBoxes
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top