abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,429
- Office Version
- 2019
- 2010
- Platform
- Windows
hello experts
I have this code works and I need fix it what I want save the file as pdf and show the message what is existed in the code and if press yes then print the file if no then exit without do any thing I appreciate if any body has suggestion
thanks in advance
I have this code works and I need fix it what I want save the file as pdf and show the message what is existed in the code and if press yes then print the file if no then exit without do any thing I appreciate if any body has suggestion
VBA Code:
Private Sub CommandButton1_Click()
If ListBox1.ListCount = 0 Then
MsgBox "No data to print"
Exit Sub
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim l2 As Workbook, ans As Variant, sPath As String, sname As String
ans = MsgBox("you sure print", vbQuestion + vbYesNo)
If ans = vbNo Then Exit Sub
sPath = "C:\Users\ose\Desktop\"
sname = Sheets("Sheet1").Range("H2").Value
Sheets("Sheet1").Copy
Set l2 = ActiveWorkbook
l2.Sheets(1).Rows("2:" & Rows.Count).ClearContents
Range("A2").Resize(ListBox1.ListCount, ListBox1.ColumnCount).Value = ListBox1.List
l2.Sheets(1).ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=sPath & sname, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
l2.Close False
End Sub