السلام عليكم
كود طباعة وكود تحويل pdf
Sub Print_Managers_Deputies()
Dim wsData As Worksheet, wsReport As Worksheet
Dim lastRow As Long, i As Long
Dim idVal As String, roleVal As String
Application.ScreenUpdating = False
Application.EnableEvents = False
Set wsData = ThisWorkbook.Sheets("data")
Set wsReport = ThisWorkbook.Sheets("التقرير مدير وكيل")
lastRow = wsData.Cells(wsData.Rows.Count, "A").End(xlUp).Row
For i = 3 To lastRow
idVal = wsData.Cells(i, "A").Value
roleVal = wsData.Cells(i, "E").Value
If (InStr(1, roleVal, "مدير", vbTextCompare) > 0) _
Or (InStr(1, roleVal, "وكيل", vbTextCompare) > 0) Then
wsReport.Range("L2").Value = idVal
wsReport.PrintOut
wsReport.Range("L2").Value = 1
End If
Next i
MsgBox "تمت طباعة جميع المديرين والوكلاء.", vbInformation
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Sub sav_PDFall2()
Dim wsData As Worksheet, wsReport As Worksheet
Dim lastRow As Long, i As Long
Dim roleVal As String
Dim folderPath As String, pdfPath As String
Dim safeName As String
Application.ScreenUpdating = False
Application.EnableEvents = False
Set wsData = ThisWorkbook.Sheets("data")
Set wsReport = ThisWorkbook.Sheets("التقرير مدير وكيل")
wsReport.Unprotect password:="0"
folderPath = ThisWorkbook.Path & "\التقرير مدير وكيل"
If Dir(folderPath, vbDirectory) = "" Then MkDir folderPath
lastRow = wsData.Cells(wsData.Rows.Count, "A").End(xlUp).Row
For i = 3 To lastRow
roleVal = wsData.Cells(i, "E").Value
If (InStr(1, roleVal, "مدير", vbTextCompare) > 0) _
Or (InStr(1, roleVal, "وكيل", vbTextCompare) > 0) Then
wsReport.Range("C9").Value = wsData.Cells(i, "B").Value
safeName = wsReport.Range("C9").Value
safeName = Replace(safeName, "/", "-")
safeName = Replace(safeName, "\", "-")
safeName = Replace(safeName, ":", "-")
safeName = Replace(safeName, "*", "-")
safeName = Replace(safeName, "?", "-")
safeName = Replace(safeName, """", "-")
safeName = Replace(safeName, "<", "-")
safeName = Replace(safeName, ">", "-")
safeName = Replace(safeName, "|", "-")
pdfPath = folderPath & "\" & safeName & ".pdf"
wsReport.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=pdfPath, _
Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next i
MsgBox "تم حفظ جميع ملفات PDF للمديرين والوكلاء في:" & vbCrLf & folderPath, vbInformation
wsReport.Protect password:="0"
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
الملف
طباعة وظائف محددة.xlsm