Onderstaande code maakt een n-aantal pdf’s aan (minimaal 1, maximaal 6) van dezelfde sheet maar met steeds een andere naam. De uitvoering gaat soms wel goed en snel maar soms ook niet en blijft de procedure hangen: not responding. Ik had al DoEvents toegevoegd binnen de loop maar dat helpt dus ook niet helemaal… Wat is er fout?
Code:
Sub MaakPDFs()
Dim strPath As String
Dim myString As String
Dim newString As String
Dim strName As String
Dim rJaren As Range
Dim j As Integer
Dim ws As Worksheet
Application.ScreenUpdating = False
If Range("pdfakkoord") = "nok" Then
MsgBox "Gegevens zijn niet compleet." & vbNewLine & _
"Vul aan en probeer opnieuw..."
Exit Sub
End If
strPath = ActiveWorkbook.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
Set ws = Sheets("Invoer")
Set rJaren = Range("jaren_meenemen")
j = Range("regels_nodig").Value
For j = 1 To j Step 1
myString = rJaren(j, 1).Value
Range("pdfnaam").Value = myString & "_" & Range("voorstelnaam")
strName = Range("pdfnaam").Value
newString = Replace(strName, ".", "")
strPathFile = strPath & newString
ws.ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:=strPathFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
DoEvents
Next j
MsgBox "Klaar!"
Application.ScreenUpdating = True
End Sub