Is there any free tool to generate pdf documents from excel data
I found some with price (http://xlvba.net/excel_to_word_automation.html) for it but not free one, can you help ?
Regards,
Ragavendra
The following code will export your chosen Sheet as PDF:
FPath = C:\Users\HomeUser\Desktop"
'set path
FName = "NewFilename.pdf"
'set filename
'EXPORT AS PDF
FName = FPath & "\" & FName
Sheets("Sheet1").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=FName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Related
The following code successfully saves an excel sheet as PDF. I would like to save it as a file, that can be opened by everyone, but not edited with the "fill and sign" feature, that is provided by Adobe Acrobat Reader DC. I have tried to simply add the following, but that does not work:
Attributes:=vbReadOnly
Here is the rest of the code:
Dim sPath As String
sPath = "O:\"
With Worksheets("Sheet 1")
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=sPath & UserForm.TextBox1.Value & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With
You should be able to use SetAttr after saving.
SetAttr "c:\path\yourfilename.pdf", vbReadOnly
I know how to save the Excel file as a PDF in VBA but was told that this is not sufficient for when sending the Excel file to another person. I will have to save it as a PDF in the same directory as the Excel sheet itself.
How does this work? I don't even know where to begin.
Sub SaveAsPdf()
File_name = ActiveWorkbook.Name
If InStr(Filename, ".") > 0 Then
Filename = Left(Filename, InStrRev(Filename, ".") - 1)
End If
File_name = ActiveWorkbook.Path & Filename & ".pdf"
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=File_name, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
I am trying to save my Excel file as a PDF but with custom file name.
I would only add a piece to the prompted filename from the Excel file.
According to the queries here:
Save excel as PDF in current folder using current workbook name
Save excel as PDF in current folder using current workbook name
My code looks as follows:
Sub DPPtoPDF()
ThisWorkbook.Sheets.Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & ThisWorkbook.Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
Sheets("Frontsheet").Select
End Sub
From this code we know the PDF filename will be the Excel filename.
I tried something like this:
ThisWorkbook.Sheets.Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= &fName $ "-Route-Aprooval.pdf" _
ThisWorkbook.Path & "\" & ThisWorkbook.Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
I get an error as per in the picture below.
I can see something is up, as my code is turning red.
The code:
ThisWorkbook.Sheets.Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
" &fName $ "-Route-Aprooval.pdf""
ThisWorkbook.Path & "\" & ThisWorkbook.Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
also doesn't work.
Any code behind the Filename:= destroys whole code.
I want to keep the name as in Excel, but add another part of the name after dash (per the image above).
Where should I place my new output filename?
Try the code below.
Sub DPPtoPDF()
Dim Custom_Name as string
ThisWorkbook.Sheets.Select
Custom_Name= ThisWorkbook.Name & "-route approval" & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & Custom_Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
Sheets("Frontsheet").Select
End Sub
I'm trying to export a sheet to PDF, but when I run the code I keep getting a 1004 error.
I believe that it is linked to the folder path to the save destination. I've tried defining the file path in different ways but still get the error.
This code is supposed to pull a part of the file name from cell B1 and the file path from the location of the worksheet. The PDF is supposed to be saved to the location of the worksheet. I'm fairly new to VBA. Any help is appreciated!
Here is the code
Sub ExportAsPDFTest()
Dim Name As String
Dim Preface As String
Name = Cells(1, "B").Value
Preface = "PreR Summer 2019 - "
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:=ActiveWorkbook.Path & Preface & Name & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=1, _
OpenAfterPublish:=False
End Sub
You're missing a backslash \ (or / if you're on Mac) after ActiveWorkbook.Path. You can use Application.PathSeparator so it will work on both:
Sub ExportAsPDFTest()
Dim Name As String
Dim Preface As String
Name = Cells(1, "B").Value
Preface = "PreR Summer 2019 - "
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & Application.PathSeparator & Preface & Name & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=1, _
OpenAfterPublish:=False
End Sub
Hope this helps.
Please add msgbox Activeworkbook.path to check your save path, you need add one more "\"
This code only saves with the workbook name and not the text "Sample". What am I doing wrong? All answers appreciated
Thanks,
Ed
Sub SamplePDF()
Dim strFolder As String
Dim i As Long
'Find the position of the period in the file name
i = InStr(ActiveWorkbook.Name, ".")
Filename = Left(ActiveWorkbook.Name, i - 1) & "Sample"
Sheets("Sample").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Quality _
:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
You are not telling VBA the filename. Append Filename:= Filename (although I would change the variable name for better reading to, for example, wbFilename:
i = InStr(ActiveWorkbook.Name, ".")
wbFilename = Left(ActiveWorkbook.Name, i - 1) & "Sample"
Sheets("Sample").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Quality _
:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True, Filename:=wbFilename
For trace with the additional argument:
Filename = Left(ActiveWorkbook.Name, i - 1) & "Sample.pdf"
Sheets("Sample").ExportAsFixedFormat Type:=xlTypePDF, Quality _
:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True, Filename:=FileName
Edit: #SJR mentioned your may need to add the extension in Filename
Also, I've condensedSheet("Sample").Select / ActiveSheet. (which was probably incorrect anyway, I believe it should have been Sheet("Sample").Activate).