john316swan
Board Regular
- Joined
- Oct 13, 2016
- Messages
- 66
- Office Version
- 2019
- Platform
- Windows
I updated an image, and now my code no longer works when exporting to PDF. All of the other images and data export, but a single image (that takes up the whole page) does not get exported. I can't seem to find a solved answer anywhere, please help!
Here is my code:
Here is my code:
VBA Code:
Option Explicit
Public problemChild As Integer
Sub DigitalPrint()
Dim OL As Worksheet, CW As Worksheet
Dim ExportCopy As String, fName As String
Dim StartRow As Integer, EndRow As Integer, x As Integer
Dim FSO As Scripting.FileSystemObject
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OL = Worksheets("ValueLetter")
Set FSO = New Scripting.FileSystemObject
If problemChild = 0 Then
StartRow = Range("StartRow")
Else
StartRow = problemChild
End If
EndRow = Range("EndRow")
'Here we create a directory for the exports on the users Desktop with today's date
ExportCopy = Environ("UserProfile") & "\Desktop\Value Letters\" & Format(Now, "mm-dd-yyyy") & "\"
If Not FSO.FolderExists(ExportCopy) Then CreateFolderRecursive (ExportCopy)
'Now we begin the export loop
OL.Select
For x = StartRow To EndRow
On Error GoTo errorMessage
Range("RowIndex") = x
If Range("ErrorCount") > 0 Then GoTo errorMessage
'As a safeguard, will pause one second to ensure the right data is being exported
'Application.Wait (Now + TimeValue("0:00:01"))
fName = Range("BF9") & ", " & Range("BF8") & " " & Range("BG7") & " Value Letter"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:=ExportCopy & fName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False
Next x
MsgBox "PDFs Exported!"
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Exit Sub
errorMessage:
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
problemChild = x
MsgBox ("Critical error on student number: " & x & " (" & Range("BG7") & " " & Range("BG8") & ") . You will need to restart the loop at this student once you fix the error!")
End Sub