Reputation: 61
I can not export to PDF, in horizontal format all my range selection, Where am I doing wrong?
Sub Macro()
Dim wksht As Worksheet
Set wksht = ActiveSheet
Dim path As String
path = "C:\test\"
If Len(Dir(path, vbDirectory)) = 0 Then
MkDir path
End If
Dim rngeStart
Dim rngeEnd
Set rngeStart = wksht.UsedRange.Find(What:="####", LookIn:=xlValues, LookAt:=xlWhole)
Set rngeEnd = wksht.UsedRange.FindNext(After:=rngeStart)
Dim dataRange As Range
Set dataRange = wksht.Range(rngeStart, rngeEnd)
Dim wb As Workbook
Dim i As Long
For i = 1 To wksht.Range("A" & wksht.Rows.Count).End(xlUp).Row
wksht.Copy
With ActiveSheet
.Range(.Cells(1, 1), .Cells(1, rngeStart.Column - 1)).EntireColumn.Delete
.Rows("1:" & rngeStart.Row - 1).Delete
End With
This part for Export in PDF, only one page without all range selection:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=path & wksht.Range("A" & i).Value & ".pdf", _ Quality:=xlQualityStandard,
IncludeDocProperties:=True, IgnorePrintAreas:=False
ActiveWorkbook.Close
Next i
End Sub
is there a function "fit to onepage" export in pdf?
Upvotes: 2
Views: 1513
Reputation: 1316
Did you try to adjust the activesheet format before pdf export ? Please add this code in the begining of your sub Macro() :
'START FORMAT THE ACTIVE SHEET
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape 'xlPortrait
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.PrintCommunication = True
'END FORMAT THE ACTIVE SHEET
Upvotes: 4