السلام عليكم ورحمة الله وبركاته وبها نبدأ
جربى هذا التعديل
Sub SaveInvoiceBothWaysAndClear()
Dim NewFN As String
Dim Sh As Worksheet
Application.DisplayAlerts = False
Set Sh = ThisWorkbook.Worksheets("INVOICE")
' Path and Name of the Files
NewFN = "C:\Users\A12\Documents\invoice\Inv" & Sh.Range("E5").Value
With Sh
' Create the PDF First
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN & ".pdf"
' Export the Excel File
.Copy
End With
' Deleting Shapes
With ActiveSheet
With .Shapes.Range(Array("Rounded Rectangle 1", "Rounded Rectangle 2", "Rounded Rectangle 5", "Rounded Rectangle 6", "Button 1", "Button 2"))
.Select
.Delete
End With
' Save the Excel File
.SaveAs NewFN & ".xlsx", FileFormat:=xlOpenXMLWorkbook
End With
' Close the Excel File
ActiveWorkbook.Close
' Increment the invoice number
Sh.Range("E5").Value = Sh.Range("E5").Value + 1
' Clear out the invoice fields
Sh.Range("A21:f37").ClearContents
Application.DisplayAlerts = True
End Sub