Hello everyone I'm new to the FORUM an recently bought the book EXCEL VBA 24hr Trainer 2nd Edition and I'm learning VBA a lot. I'm a Maintenance Supervisor and I'm creating a Worksheet to capture all the repairs in my building also I'm using VBA to create userforms for Data Entry, Search and Printing the Worksheet.
At the moment the Worksheet has 350 rows of information so If a User wants to print just some information it can be done through VBA.
I'm Printing a range called Filter_Stuff after I created a PDF but the printing area is overlapping the Headers. I don't know what I'm doing wrong
This is my code:
http://i280.photobucket.com/albums/k...pstapiyfjd.jpg
http://i280.photobucket.com/albums/k...psjpfugzwm.jpg
Code:
Sub PrintPDFAll()
'*******************
'turn off screen updating
Dim Opendialog
Dim MyRange As Range
Application.ScreenUpdating = False
FolderPath = Application.ActiveWorkbook.Path
'open dialog and set file type
Opendialog = Application.GetSaveAsFilename("", filefilter:="PDF Files (*.pdf), *.pdf", _
Title:="My Data")
'if no value is added for file name
If Opendialog = False Then
MsgBox "The operation was not successful"
Exit Sub
End If
'set the named range for the PDF print area
Sheet1.Select
With Sheet1
.Range("AS1:BI" & Cells(Rows.Count, "AS").End(xlUp).Row).Name = "Filter_Stuff"
End With
'set range
Set MyRange = Sheet1.Range(" Filter_Stuff ")
With Sheet1.PageSetup
.PrintArea = "Filter_Stuff"
.LeftHeader = "&""Bold""&20CCBQ - Peter J. Striano"
.CenterHeader = "Page &P of &N"
.RightHeader = "Printed &D &T"
.LeftFooter = "Path : " & FolderPath 'ActiveWorkbook.Path"
.CenterFooter = "Workbook Name: &F"
.RightFooter = "Sheet: &A"
End With
'create the PDF
On Error Resume Next
MyRange.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Opendialog, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
'error handler
On Error GoTo 0
'clear the page breaks
ActiveSheet.DisplayPageBreaks = False
Application.ScreenUpdating = False
Sheet1.Select
End Sub