omagoodness
Board Regular
- Joined
- Apr 17, 2016
- Messages
- 56
Hello
I have a sheet that calculates payroll deductions. I want to archive the data and reset the sheet for the next pay period. The following code generates the "Archived message" and then the error message but does not generate the pdf file. Also, the code snippet to clear the data also clears the header row. I've been looing at this for 2 days now and cannot see where the errors are. Can anyone help, please and thank you? Would attach sample file but I don't see the attachment option.
I have a sheet that calculates payroll deductions. I want to archive the data and reset the sheet for the next pay period. The following code generates the "Archived message" and then the error message but does not generate the pdf file. Also, the code snippet to clear the data also clears the header row. I've been looing at this for 2 days now and cannot see where the errors are. Can anyone help, please and thank you? Would attach sample file but I don't see the attachment option.
VBA Code:
Private Sub cmdArchivePay_Click()
'declare the variables
'***************************************************************
'Locate the data to Archive
Dim Awb As Workbook
Set Awb = ActiveWorkbook
Dim Asht As Worksheet
Set Asht = Awb.Sheets("Payroll Calculation")
Dim Myrng As Range
Set Myrng = Asht.Range("A1,O27")
'Define the save location and name of the archived data
Dim strFile As String, Myfile As Variant
strFile = ThisWorkbook.Path & "\Payroll Archives" & "\" & Myfile
Myfile = "Period Ending " & PE & ".pdf"
'**************************************************************************
'Export the data, in pdf format, to the Payroll Archives
On Error GoTo errHandler
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Myrng.ExportAsFixedFormat Type:=xlTypePDF, filename:=Myfile, Quality:=xlQualityStandard, _
IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
MsgBox "Data has been archived", vbOKOnly, "Payroll Archives"
'********************************************************************************
'After data has been archived, reset the table '__________________________________________________
'|How can I not clear the header row of the table?|
ActiveWorkbook.Sheets("Payroll Calculation").Range("tblPayroll").Select '|________________________________________________|
Cells.SpecialCells(xlCellTypeConstants).ClearContents
Application.DisplayAlerts = True
Application.ScreenUpdating = True
'***************************END OF EXPORT CODE ******************************************************
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub