Add PDF to Button

L

Legacy 436357

Guest
Could print to PDF be added to this button?

My print area is B2:H53

Code:
Private Sub CommandButton1_Click()
   Dim NxtRw As Long
   Application.EnableEvents = False
   If Range("J3").Value = "" Then
      NxtRw = 3
   Else
      NxtRw = Range("J2").End(xlDown).Offset(1).Row
   End If
   Range("J" & NxtRw).Value = Range("H6").Value
   Range("K" & NxtRw).Value = Range("H3").Value
   Range("L" & NxtRw).Value = Format(Now(), "MM/dd/yyyy HH:MM:SS")

   Application.EnableEvents = True
End Sub
 
Thanks Fluff but it highlights that whole thing in debug. Identifier under cursor is not recognized.
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Just this:

Range("B2:H53")
Type:=xlTypePDF, Filename:= "C:\Users\xj\Desktop\Test PDF Name", _
Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
 
Upvote 0
Look at posts 4, 6, 10. You are missing the .ExportAsFixedFormat command after your range.
 
Last edited:
Upvote 0
@ekrause
You need the Exportasfixedformat otherwise the while section will go red as VBA doesn't know what to do with the range.
@xjohnson
I cannot replicate that error, but try
Code:
Range("B2:H53").ExportAsFixedFormat Type:=xlTypePDF, FileName:=Environ("userprofile") & "\Desktop\Test", _
   Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas _
    :=False, OpenAfterPublish:=True
Which should save the pdf to your desktop.
 
Upvote 0
Thank you Joe for finding that. The post #10 solved the problem thanks to Fluff.

I really appreciate the help.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,857
Members
449,051
Latest member
excelquestion515

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