I'm trying to save a worksheet as PDF and I was successful at doing this, but when I open the generated PDF file all the textboxes in the sheet are deformed.
How can I keep the ratio of the exported textboxes?
I'm using a button in the worksheet that executes the following code:
ThisWorkbook.Sheets(1).Select
Sheets(1).Activate
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="\\10.18.105.44\Setor Proteção RDs\01 - Ordens de Ajustes\Banco de ordens\AL" & alimentador & "\" & nome_arquivo & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Sheets(1).Select
Range("D2").Select
I discovered that this only occurs when i try to save with the zoom of the workbook larger than 100%, when i print with zoom at 100% it goes like a charm.
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've been using some code to save an active worksheet to PDF, using the current date/time as the filename, and saving into a SharePoint folder.
Sub Save()
Dim strFilename As String
strFilename = Format(Now(), "yyyy-mm-dd hhmm")
Sheets("Weather Warning Action Sheet").Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"https://xxx.sharepoint.com/sites/xxx/xxx/Paperwork and Admin/WX Warnings/2020/" & strFilename & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
End Sub
This code has been working fine for a while, but has suddenly come up with the "Run-time error '1004': Document not saved" error message.
Debugging shows this as the error:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"https://xxx.sharepoint.com/sites/xxx/xxx/Paperwork and Admin/WX Warnings/2020/" & strFilename & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Any assistance would be greatly appreciate.
Many thanks,
James
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 want to create a PDF file with excel data. I have rows of data in excel, for each row I want to create a PDF file and save it to my machine. How to do it with excel or access macro in vba?
You may use File / Export / Create PDF/XPS Document menu for this purpose.
When this feature is used when recording a VBA macro, below code is generated, you may use it or get your own code by recording a macro. Then you may use the code within a loop to create multiple PDFs with one go.
This feature creates the PDF using the printable area of your sheet. So you may have to adjust the print area from your code before each PDF creation.
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"\\test.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
This will do what you want.
Sub Save_Each_Row_As_PDF()
myrange = "A1:J10"
lastRow = Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row
For myRow = 2 To lastRow
Range("A" & myRow & ":J" & myRow).Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\your_path_here\Book" & myRow & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Next
End Sub
I have the below code I have researched and got to work in one of my workbooks. The idea of the code is to automatically print a sheet to PDF and save down in a directory of my choosing naming it the contents of a specific cell.
All works fine until I try to copy into a new workbook (I designed in a test workbook as not to corrupt the original) then I get a
run time error 1004
and the ThisWorkbook.Sheets(Array("sheet 2")).Select is highlighted when I debug. Am I missing something simple? as the code works in the original workbook but not in if I paste into a new module in a new workbook? Sorry i'm quite new to this!
sub PrintPDFRT()
Sheets("test").Activate
ActiveSheet.UsedRange.Select
Sheets("malbru1").Activate
ActiveSheet.UsedRange.Select
Sheets("sheet 2").Activate
Range("A1:j137").Select
ThisWorkbook.Sheets(Array("sheet 2")).Select
Selection.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="FIle path\" & Range("L7").Value, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub
Try it like this: (without Array)
sub PrintPDFRT()
WorkSheets("test").Activate
ActiveSheet.UsedRange.Select
WorkSheets("malbru1").Activate
ActiveSheet.UsedRange.Select
WorkSheets("sheet 2").Activate
Range("A1:j137").Select
ThisWorkbook.WorkSheets("sheet 2").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="FIle path\" & Range("L7").Value, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub