Dim Sh As Boolean
Public Property Get f() As Worksheet
Set f = Sheets("Sheet1") <========= إسم ورقة العمل المرغوب جلب إسم المصنف الجديد منها
End Property
Private Sub UserForm_Initialize()
Dim WS As Worksheet, CrWS As Variant, i As Integer
' قم بتعديل أسماء أوراق العمل المرغوب إظهارها
CrWS = Array("Sheet1", "Sheet2", "Sheet3")
For Each WS In ThisWorkbook.Worksheets
For i = LBound(CrWS) To UBound(CrWS)
If WS.name = CrWS(i) Then
ListBox1.AddItem WS.name
Exit For
End If
Next i
Next WS
HideBar Me
End Sub
Private Sub CommandButton1_Click()
Dim i As Integer, ShName As String, newWb As Workbook, sPath As String
Dim tmps As Integer, shArr As String, sCount As Integer, WBname As String
WBname = f.[R2].Value <======= قم بتعديل عنوان خلية الإسم بما يناسبك
If WBname = "" Then: MsgBox "الرجاء إدخال إسم المصنف ", vbExclamation, "إنتباه": Exit Sub
'Code........
..............
End Sub
Private Sub CommandButton2_Click()
On Error GoTo SupApp
Dim arr As New Collection, TempWb As Workbook, WS As Worksheet
Dim i As Integer, sMsg As Integer, tbl As Boolean
Dim WBname As String, sPath As String, shArr As String
WBname = Trim(f.Range("R2").Value)
If WBname = "" Then MsgBox "الرجاء إدخال اسم المصنف", vbExclamation, "تنبيه": Exit Sub
tbl = Me.CheckBox1.Value
For i = 0 To Me.ListBox1.ListCount - 1
If tbl Or Me.ListBox1.Selected(i) Then
arr.Add Me.ListBox1.List(i)
shArr = shArr & Me.ListBox1.List(i) & "- "
sMsg = sMsg + 1
End If
Next
If sMsg = 0 Then MsgBox "الرجاء تحديد ورقة عمل واحدة على الأقل", vbExclamation, "تنبيه": Exit Sub
If Len(shArr) > 0 Then
shArr = Left(shArr, Len(shArr) - 2)
End If
If MsgBox("هل أنت متأكد أنك تريد حفظ الأوراق التالية؟" & _
vbNewLine & vbNewLine & shArr, vbYesNo + vbQuestion, "PDF" & " تأكيد الحفظ") = vbNo Then Exit Sub
With Application
.ScreenUpdating = False: .EnableEvents = False: .DisplayAlerts = False: .Calculation = xlCalculationManual
End With
Set TempWb = Workbooks.Add(xlWBATWorksheet)
For i = 1 To arr.Count
ThisWorkbook.Sheets(arr(i)).Copy After:=TempWb.Sheets(TempWb.Sheets.Count)
Next
sPath = ThisWorkbook.path & "\" & WBname & ".pdf"
If Dir(sPath) <> "" Then Kill sPath
TempWb.ExportAsFixedFormat Type:=xlTypePDF, fileName:=sPath, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
TempWb.Close False
MsgBox "تم حفظ الملفات بنجاح", vbInformation, "PDF حفظ"
Unload Me
CleanUp:
With Application
.ScreenUpdating = True: .EnableEvents = True: .DisplayAlerts = True: .Calculation = xlCalculationAutomatic
End With
Exit Sub
SupApp:
On Error Resume Next: If Not TempWb Is Nothing Then TempWb.Close False
Resume CleanUp
End Sub
تصدير صفحات v3.xlsm