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:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Attachments

  • B10.PNG
    B10.PNG
    10.5 KB · Views: 3
Upvote 0
In that case I would expect your code to produce the pdf files.
 
Upvote 0
In that case I would expect your code to produce the pdf files.
I am getting no pdf files exported instead I got a message: "Program has finished. 0 files were generated".
 
Upvote 0
If you step through the code does it ever get to this part
VBA Code:
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
 
Upvote 0
If you step through the code does it ever get to this part
VBA Code:
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
it stops at .show where I am asked to select a folder name and it's end.
 

Attachments

  • Show.PNG
    Show.PNG
    33.2 KB · Views: 2
Upvote 0
Did you get any error messages?
 
Upvote 0
it stops at .show where I am asked to select a folder name and it's end.
I copied all values in AA to AB and ran it then it worked exporting to pdf files that tells me it looks into AB and AB is 28. How do I direct it to AA - 27?
 
Upvote 0
It's looking at AB for Choice & AA for ipa
 
Upvote 0
Solution

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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