VBA Button to print selected range (that changes) Excel Mac

esmarques

New Member
Joined
Oct 27, 2020
Messages
34
Office Version
  1. 365
Platform
  1. MacOS
Hello,

Hello,

Does anyone know how to add the VBA code to perform the printing task on the code below?
I am using Excel for Mac V16.42
Please note that the range to be printed needs to be from A1 to last row with data as the content of the table will change depending on what user add in.

This is my first post here, if there is anything missing or not right on this post, please just let me know.

Any help welcomed. Thank you very much.

[Sub Button1_Click()
Dim LstRw As Long
Dim Rng As Range
Const NameAdd = "A4"
Dim FileName As String
Dim WkP As String
Dim Answer As VbMsgBoxResult

Answer = MsgBox("Save Quote?", vbYesNo)

If Answer = vbYes Then
LstRw = Cells(Rows.Count, "A").End(xlUp).Row
Set Rng = Range("A1:G" & LstRw)
ActiveSheet.PageSetup.PrintArea = Rng.Address

WkP = "/Volumes/GoogleDrive/My Drive/Nas My Cloud/Global Grooves/Costumes and Making/Packing Lists"
FileName = Range(NameAdd) & "_" & Format(Now(), "YYMMDD") & ".pdf"
FileName = WkP & Application.PathSeparator & FileName
ActiveSheet.PageSetup.PrintArea = Rng.Address
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True


Range("H5,H1,H9:H21").Select
Selection.ClearContents
Range("E1").Select

End If
End Sub]
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You might try this ...
Rich (BB code):
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True

ActiveSheet.PrintOut

Range("H5,H1,H9:H21").Select
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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