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 not on the sheet, it's in your code & is printed to the immediate window with this line Debug.Print counter so you should be able to see it there.
I found it with your help.

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

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
And what did it say in the immediate window?
 
Upvote 0
And what did it say in the immediate window?
I am not sure what is immediate window?

Here is what happening after Debug.Printer counter.

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)
Practice = Cells(i, 27)

Cells(2, 1) = Choice
If Cells(10, 2).Value = 0 Then
GoTo EmptyPractice
Else
 
Upvote 0
In the VB editor use Ctrl G to bring up the immediate window (normally positioned below the main code window). The step through the code till you get to this lineIf Direct = vbNullString Then GoTo DirErrorand look in the immediate window, what does it show?
 
Upvote 0
In the VB editor use Ctrl G to bring up the immediate window (normally positioned below the main code window). The step through the code till you get to this lineIf Direct = vbNullString Then GoTo DirErrorand look in the immediate window, what does it show?
it shows a 1
 
Upvote 0
That's why you are not getting anything as Col Z is empty.
What column should you be looking at to find the last row, presumably either AA or AB?
 
Upvote 0
That's why you are not getting anything as Col Z is empty.
What column should you be looking at to find the last row, presumably either AA or AB?
column AA should be. Please help how to correct my code to point to Col AA.
 

Attachments

  • column AA.PNG
    column AA.PNG
    5.5 KB · Views: 4
Upvote 0
In that case just change the 26 to 27 on this line of code
VBA Code:
counter = Cells(Rows.Count, 26).End(xlUp).Row
 
Upvote 0
In that case just change the 26 to 27 on this line of code
VBA Code:
counter = Cells(Rows.Count, 26).End(xlUp).Row
I am getting 0 files generated after changing the 26 to 27.

do I need to change/update the code below?

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

Cells(2, 1) = Choice
If Cells(10, 2).Value = 0 Then
GoTo EmptyPractice
 
Upvote 0
What does the immediate window say now?
 
Upvote 0

Forum statistics

Threads
1,216,069
Messages
6,128,599
Members
449,460
Latest member
jgharbawi

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