Andre175
Gebruiker
- Lid geworden
- 2 feb 2018
- Berichten
- 351
Bij onderstaande macro krijg ik en foutmelding.
Terwijl deze macro het gewoon doet wat ie moet doen.
waar moet ik de fout zoeken?
Code:
Sub RDB_Selection_Range_To_PDF_And_Create_Mail_Contactpersonen()
Dim sh As Worksheet
Dim FileName As String
If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more then one sheet selected," & vbNewLine & _
"ungroup the sheets and try the macro again"
Else
'Call the function with the correct arguments
'For a fixed range use this line
ar3 = Sheets("Evenementen").ListObjects(1).DataBodyRange
With Sheets("Deelnemers per Evenement")
For j = 1 To UBound(ar)
If ar3(j, 1) >= .[B2] And ar3(j, 1) <= .[B3] And (.[D2] = "alle contactpersonen" Or .[D2] = ar3(j, 4)) Then
.Range("B8").Value = ar3(j, 1)
' Als er geen opgave is dan door naar volgende
If .Range("B459").Value = 0 Then GoTo einde
FileName = RDB_Create_PDF(Source:=Range("A8:I500"), _
FixedFilePathName:=Sheets("Deelnemers per evenement").Range("B1").Value & Sheets("Deelnemers per evenement").Range("Q4").Value & ".pdf", _
OverwriteIfFileExist:=True, _
OpenPDFAfterPublish:=False)
'For the selection use Selection in the Source argument
'FileName = RDB_Create_PDF(Source:=Selection)
'For a fixed file name use this in the FixedFilePathName argument
'FixedFilePathName:="C:\Users\Ron\Test\YourPdfFile.pdf"
If FileName <> "" Then
RDB_Mail_PDF_Outlook FileNamePDF:=FileName, _
StrTo:=Sheets("Deelnemers per Evenement").Range("Q3").Value, _
StrCC:="", _
StrBCC:="", _
StrSubject:=Sheets("Deelnemers per Evenement").Range("E3").Value, _
Leesbev:="", _
Signature:=True, _
Send:=Sheets("Deelnemers per Evenement").Range("R1").Value, _
strbody:=Sheets("Deelnemers per Evenement").Range("I1").Value & "<br>" & Sheets("Deelnemers per Evenement").Range("I2").Value & "<br>" & Sheets("Deelnemers per Evenement").Range("I3").Value & "<br>" & Sheets("Deelnemers per Evenement").Range("I4").Value & "<br>" & Sheets("Deelnemers per Evenement").Range("I5").Value & "<br>" & Sheets("Deelnemers per Evenement").Range("I6").Value
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exist"
End If
End If
einde:
Next j
End With
End If
End Sub
Terwijl deze macro het gewoon doet wat ie moet doen.
Code:
Sub RDB_Selection_Range_To_PDF_And_Create_Mail_Ouders()
Dim sh As Worksheet
Dim FileName As String
If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more then one sheet selected," & vbNewLine & _
"ungroup the sheets and try the macro again"
Else
'Call the function with the correct arguments
'For a fixed range use this line
ar = Sheets("Indeling kinderen").ListObjects(1).DataBodyRange
With Sheets("Brief")
For j = 1 To UBound(ar)
If ar(j, 1) >= .[M5] And ar(j, 1) <= .[M6] And (.[M7] = "Alle scholen" Or .[M7] = ar(j, 4)) And (.[M8] = "Alles" Or .[M8] = ar(j, 8)) Then
.Range("H1").Value = ar(j, 1)
'Als er geen opgave is dan door naar volgende
If .Range("R21").Value = 0 Then GoTo einde
FileName = RDB_Create_PDF(Source:=Range("A1:G41"), _
FixedFilePathName:=.Range("N11").Value & .Range("R1").Value & ".pdf", _
OverwriteIfFileExist:=True, _
OpenPDFAfterPublish:=False)
'For the selection use Selection in the Source argument
'FileName = RDB_Create_PDF(Source:=Selection)
'For a fixed file name use this in the FixedFilePathName argument
'FixedFilePathName:="C:\Users\Ron\Test\YourPdfFile.pdf"
If FileName <> "" Then
RDB_Mail_PDF_Outlook FileNamePDF:=FileName, _
StrTo:=Sheets("Brief").Range("R2").Value, _
StrCC:="", _
StrBCC:="", _
StrSubject:=Sheets("Brief").Range("R3").Value, _
Leesbev:=Sheets("Brief").Range("N24").Value, _
Signature:=True, _
Send:=Sheets("Brief").Range("AC2").Value, _
strbody:=Sheets("Brief").Range("M26").Value & "<br>" & Sheets("Brief").Range("M27").Value & "<br>" & Sheets("Brief").Range("M28").Value & "<br>" & Sheets("Brief").Range("M29").Value & "<br>" & Sheets("Brief").Range("M30").Value & "<br>" & Sheets("Brief").Range("M31").Value
' StrBody:="<H3><B>Dear Customer</B></H3><br>" & _
' "<body>See the attached PDF file with the last figures." & _
' "<br><br>" & "Regards Ron de bruin</body>"
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exist"
End If
End If
einde:
Next j
End With
End If
End Sub
waar moet ik de fout zoeken?