Excel table to mail via Commandbutton.

TDNova

New Member
Joined
Apr 16, 2018
Messages
45
Hello, im trying to figure out how to make this code better. currently the code only takes one row,since its based on cell position.

Code:
Dim i As Integer, Mail_Object, Email_Subject, o As Variant
Dim TypeS As String
TypeS = ActiveSheet.ListObjects("Orderoversikt").ListColumns(1).Range.Column
 
    Set Mail_Object = CreateObject("Outlook.Application")
        With Mail_Object.CreateItem(o)
            .Subject = ActiveSheet.ListObjects("Orderoversikt")
            .To = "Mail"
            .cc = "frommail"
            .Body = "cell1: " & ActiveSheet.Range("r4").Value & Chr(13) & Chr(10) & "cell2: " & ActiveSheet.Range("S4").Value & Chr(13) & Chr(10) & "cell3: " & ActiveSheet.Range("t4").Value & Chr(13) & Chr(10) & "cell4:" & ActiveSheet.Range("u4").Value & Chr(13) & Chr(10) & "cell5: " & ActiveSheet.Range("v4").Value & Chr(13) & Chr(10) & "cell6: " & ActiveSheet.Range("w4").Value
            .Display
    End With
        Application.DisplayAlerts = False
Set Mail_Object = Nothing
End Sub
Is it possible to make a code that would put the whole table in the mail instead of just one row.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
For example, if it's based on string with all the information, if it find more than one row, add it aswell with same format.
because it should be a way to make it dynamic.
 
Upvote 0
is it possible with a code like this ?

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)Dim Targ As Range
Set Targ = Intersect(Target, Range("x7:x20"))
'Doubleclick in column P to trigger macro
If Not Targ Is Nothing Then
    SendEmail Target.Row
    Cancel = True       'undo the doubleclick effect if macro triggered
    Sub SendEmail(Row As Long)
Dim OutApp As Object
Dim OutMail As Object
Dim msg As String
On Error GoTo cleanup
msg = "Message: " & _
    Range("r" & Row) & " - " & Range("w" & Row) & ".  Thank you."
Set OutApp = CreateObject("Outlook.Application")
With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With
Set OutMail = OutApp.CreateItem(0)
With OutMail
    .To = "mail"
    .cc = "tomail"
    .Subject = "order"
    .Body = msg
    .Display  'Or use Send
End With
Range("x" & Row).Value = "Closed"
Set OutMail = Nothing
cleanup:
Set OutApp = Nothing
With Application
    .EnableEvents = True
    .ScreenUpdating = True


End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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