semperidem46
New Member
- Joined
- Dec 22, 2017
- Messages
- 2
Hello,
I wrote a code to set dynamically Print Area, based on a cell value.
After that I want to set Page Brake.
In the and, I want to export the sheet in PDF.
In this code, PageBreake is not working.
This excel file will be used by many people, on many computers. I am trying to find a way to have same PDF print layout for everyoane.
Thankes in advance for your help.
here is my code:
I wrote a code to set dynamically Print Area, based on a cell value.
After that I want to set Page Brake.
In the and, I want to export the sheet in PDF.
In this code, PageBreake is not working.
This excel file will be used by many people, on many computers. I am trying to find a way to have same PDF print layout for everyoane.
Thankes in advance for your help.
here is my code:
S
Sub PDFActiveSheet()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandlerSet wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), "dd.mm.yyyy\_hh.mm")
'get PrintArea
If Len(Range("O9").Value) = 13 Then
ActiveSheet.PageSetup.PrintArea = "$A$1:$AM$168"
With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = 3
End With
ActiveSheet.ResetAllPageBreaks
Set ActiveSheet.HPageBreaks(1).Location = Range("A57")
Set ActiveSheet.HPageBreaks(2).Location = Range("A113")
Else
ActiveSheet.PageSetup.PrintArea = "$A$1:$AM$112"
With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = 2
End With
ActiveSheet.ResetAllPageBreaks
Set ActiveSheet.HPageBreaks(1).Location = Range("A57")
End If
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & ""
'replace spaces and periods in sheet name
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", "_")
'create default name for savng file
strFile = Range("O8").Value & "_" & strTime & ".pdf"
strPathFile = strPath & strFile
'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
'export to PDF if a folder was selected
If myFile <> "False" Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub