troyh68
New Member
- Joined
- Nov 14, 2016
- Messages
- 24
To start this is not my Macro but a macro that I have "inherited" and need to fix the macro.
With that said the macro is supposed to take all of the different Tabs in the workbook (5 tabs total) and create a PDF of the results of the data. The error is attached as an image as is the Module Window with the error pointed to the line. The full code is below. When I debug the code it is breaking on the last line of the PDF export process on the OpenAfterPublish:=True Line. I have tried a couple of different things.
1. I chose False for OpenAfterPublish The PDF didn't open and it did not save the pdf to the target location.
2. I tried With Application.DisplayAlerts = False The PDF file was still not opened or saved to the target location
3. I tried the With Application.DisplayAlerts and OpenAfterPublish:= True same error
With that said the macro is supposed to take all of the different Tabs in the workbook (5 tabs total) and create a PDF of the results of the data. The error is attached as an image as is the Module Window with the error pointed to the line. The full code is below. When I debug the code it is breaking on the last line of the PDF export process on the OpenAfterPublish:=True Line. I have tried a couple of different things.
1. I chose False for OpenAfterPublish The PDF didn't open and it did not save the pdf to the target location.
2. I tried With Application.DisplayAlerts = False The PDF file was still not opened or saved to the target location
3. I tried the With Application.DisplayAlerts and OpenAfterPublish:= True same error
VBA Code:
Sub make_report()
Dim companyname, reportname As String
Dim bli, bli2 As Integer
bli = 0
bli = 0
companyname = Worksheets("Report").Range("C2:C2")
'bli YES=6=vbYes NO=7=vbNo
bli = MsgBox(companyname, vbYesNo, "Company Name correct?")
'MsgBox bli, 0, "bli"
If (bli = 6) Then
reportname = Names.Parent.Path & "\" & Worksheets("Report").Range("C2:C2") & "_" & _
Worksheets("Report").Range("B4:B4") & "_Fraud_Report.pdf"
'bli OK=1=vbOK Cancel=2=vbCancel
bli2 = MsgBox(reportname, vbOKCancel, "Report FileName:")
If (bli2 = 1) Then
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=reportname, _
Quality:=xlQualityStandard, _
From:=1, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Else
MsgBox "NO Fraud Report made", 0, "Report Cancelled"
End If
Else
MsgBox "NO Fraud Report made", 0, "Report Cancelled"
End If
End Sub