برای ساختن فایل PDF در محیط آفیس بایستی مراحل زیر را طی نمود تا امکان ایجاد فایل PDF از فایلهای آفیس برای شما فراهم گردد.
• ابتدا بایستی که یک پرینتر مجازی PDF را روی سیستم خود نصب نمایید. انواع متنوعی از این ابزار در اینترنت موجود می باشد که می توان به win2pdf و یا pdffactory اشاره نمود.
• سپس بایستی یک فایل add-in را از اینجا دانلود نمایید. این فایل add-in، ابزار لازم را برای استفاده شما فراهم می آورد. با استفاده از این فایل شما می توانید از طریق منوی Office Button >Save As ….PDF و یا Office Button >Send ….PDF امکان ایجاد فایل PDF را داشته باشید.
• راه دیگری برای ایجاد PDF استفاده از ماکرو می باشد.در زیر شما سه ماکرو را می بینید که هر کدام بصورتی متفاوت ابزار PDF ساز محسوب می شوند.
o ماکروی اول امکان ساخت فایل PDF را از روی WorkBook فراهم می آورد. با استفاده از این ماکرو ابتدا از تمامی محتواهای موجود در شیت اول فایل PDF ساخته و سپس به سراغ شیت دوم رفته و این روش را تا پایان شیت ها ادامه می دهد. در این روش تمامی شیتها در قالب صفحات یک فایل PDF در آمده و روی هم یک فایل چند صفحه ای را بوجود می آورند.
o ماکروی دوم امکان ساخت فایل PDF از روی WorkSheet فعال را فراهم می آورد.
o ماکروی سوم امکان ایجاد فایل PDF را از روی محدوده انتخابی (Selected Range) برای شما فراهم می آورد. یعنی شما ابتدا بوسیله ماوس روی یک محدوده درگ نموده و پس از انتخاب محدوده مورد نظر می توانید فایل PDF آنرا بوجود آورید.
• برای انجام کار با ماکرو، ابتدا یک ماژول به پروژه جاری تان اضافه نموده و سپس کد زیر را به آن اضافه نمایید و سپس با قرار دادن یک دکمه روی شیت و ارتباط آن با یکی از ماکروهای موجود، براحتی می توانید از آن کد برای ایجاد فایل PDF استفاده نمایید.
[align=left]
کد:
Sub RDB_Workbook_To_PDF()
Dim FileName As String
'Call the function with the correct arguments
FileName = RDB_Create_PDF(ActiveWorkbook, True, True)
If FileName <> "" Then
'Ok, you find the PDF where you saved it
'You can call the mail macro here if you want
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"You didn't want to overwrite the existing PDF file"
End If
End Sub
Sub RDB_Worksheet_Or_Worksheets_To_PDF()
Dim FileName As String
If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more then one sheet selected," & vbNewLine & _
"be aware that every selected sheet will be published"
End If
'Call the function with the correct arguments
FileName = RDB_Create_PDF(ActiveSheet, True, True)
If FileName <> "" Then
'Ok, you find the PDF where you saved it
'You can call the mail macro here if you want
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"You didn't want to overwrite the existing PDF file"
End If
End Sub
Sub RDB_Selection_Range_To_PDF()
Dim FileName As String
If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more then one sheet selected," & vbNewLine & _
"ungroup the sheets and try the macro again"
Else
'Call the function with the correct arguments
FileName = RDB_Create_PDF(Selection, True, True)
'For a fixed range use this line
'FileName = RDB_Create_PDF(Range("A1:C12"), True, True)
If FileName <> "" Then
'Ok, you find the PDF where you saved it
'You can call the mail macro here if you want
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"You didn't want to overwrite the existing PDF file"
End If
End If
End Sub
Function RDB_Create_PDF(Myvar As Object, OverwriteIfFileExist As Boolean, _
OpenPDFAfterPublish As Boolean) As String
Dim FileFormatstr As String
Dim Fname As Variant
'Test If the Microsoft Add-in is installed
If Dir(Environ("commonprogramfiles") & "\Microsoft Shared\OFFICE" _
& Format(Val(Application.Version), "00") & "\EXP_PDF.DLL") <> "" Then
'Open the GetSaveAsFilename dialog to enter a file name for the pdf
FileFormatstr = "PDF Files (*.pdf), *.pdf"
Fname = Application.GetSaveAsFilename("", filefilter:=FileFormatstr, _
Title:="Create PDF")
'If you cancel this dialog Exit the function
If Fname = False Then Exit Function
'If OverwriteIfFileExist = False we test if the PDF
'already exist in the folder and Exit the function if that is True
If OverwriteIfFileExist = False Then
If Dir(Fname) <> "" Then Exit Function
End If
'Now the file name is correct we Publish to PDF
On Error Resume Next
Myvar.ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:=Fname, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=OpenPDFAfterPublish
On Error GoTo 0
'If Publish is Ok the function will return the file name
If Dir(Fname) <> "" Then RDB_Create_PDF = Fname
End If
End Function
[/align]
امید که مورد استفاده واقع گردد. البته مطالب گفته شده از اینترنت گرفته شده و برای خود بنده هم تازگی داشت. در پایان لازم می دانم تا از tv_Kade عزیز به خاطر طرح سئوال تشکر بعمل آورم.
علاقه مندی ها (Bookmarks)