Copy a part of sheet, print and email in one command vba code

dss28

Board Regular
Joined
Sep 3, 2020
Messages
61
Office Version
  1. 2007
Platform
  1. Windows
I am able to copy a part of the sheet and print separately using command

Application.Dialogs(xlDialogPrinterSetup).Show
ActiveSheet.PrintOut

I am also able to copy and email the selection using following code

VBA Code:
With Sheet13
'======================================= copy zone ==============================
.Range("B3:Q23").Select

Selection.Copy

'========================================================== email copied data =======================
        
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "Body content" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2"
                  On Error Resume Next
    With xOutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = " xxxx "
        .Body = " yyyy"
        .display   'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing

'=========================== email code ends===================================
End With


however I want to combine these two codes and do both the things in one command button tp prevent the user to see or modify the sheet.

I am trying to include one part of code (printing) through main userform command button - can select printer and print. After Printing I am calling another userform to open and placed my copy / email code in it. It has two command buttons - "Yes" - to copy and email and second "No"- exit without copying / emailing

However the second userform called through first userform is not copying the data but opens the outlook email.

Only the copy range code does not work.

please suggest way out.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Watch MrExcel Video

Forum statistics

Threads
1,130,112
Messages
5,640,174
Members
417,130
Latest member
Darion2021

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
Top