VBA did not export active sheets in excel to pdf

HenryT

New Member
Joined
Sep 28, 2022
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I received a message - "Program has finished. 0 files were generated" when I ran this macro in excel.
I need your help... and please let me if I need to provide further info. Thank you!

VBA Code:
Sub IPAPDF()

Dim SaveName As String
Dim Direct As String
Dim Ipa As String
Dim Choice As String
Dim counter As Long
Dim files As Integer

'Select a folder to save all your dashboards
With Application.FileDialog(msoFileDialogFolderPicker)
  .AllowMultiSelect = False
  .Show
  On Error Resume Next
  Direct = .SelectedItems(1)
  Err.Clear
  On Error GoTo 0
End With

counter = Cells(Rows.Count, 26).End(xlUp).Row
Debug.Print counter

'Check for data to force error
If Direct = vbNullString Then GoTo DirError
If Dir(Direct, vbDirectory) = "" Then GoTo DirError

files = 0

For i = 2 To counter
Choice = Cells(i, 28)
Ipa = Cells(i, 27)

Cells(2, 1) = Choice
If Cells(10, 2).Value = 0 Then
    GoTo EmptyPractice
Else
Application.ScreenUpdating = False
Application.DisplayAlerts = False
SaveName = Direct & "\" & "BUR IPA View " & Ipa & " " & Format(Date, "dd-mm-yyyy") & ".pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    SaveName, Quality:= _
    xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
files = files + 1
End If

EmptyPractice:
Next i

'If no errors occurred just exit sub
MsgBox "Program has finished. " & files & " files were generated", vbOKOnly
Exit Sub

DirError:
MsgBox ("No valid save path chosen. Exiting program")
Exit Sub

End Sub
 
Last edited by a moderator:
It's looking at AB for Choice & AA for ipa
Yes, you're correct and it makes sense.
I greatly appreciated all your time and effort for helping me to resolve my problem. I learned so much from asking questions and you took times to answer me without hesitations.
You have a good day!
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Glad it's sorted & thanks for the feedback.
 
Upvote 0
Yes, you're correct and it makes sense.
I greatly appreciated all your time and effort for helping me to resolve my problem. I learned so much from asking questions and you took times to answer me without hesitations.
You have a good day!
And, I changed the marked solution with the most instructive post in this "debug" thread. The whole thread contains many useful sections to show how to debug a code and find the problem. @HenryT: thanks for the question and carefully following the instructions provided by @Fluff; and @Fluff: thanks for the step-by-step debugging that will also help future readers.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top