boppe
Gebruiker
- Lid geworden
- 26 aug 2010
- Berichten
- 69
Mijn excel formulier maakt steeds een unieke naam (datum+serienummer+postcode+huisnr) aan en wordt opgeslagen als een pdf file.
Nu willen we eigenlijk dat VBA deze PDF file ook automatisch gaat e-mailen.
Er bestaan scriptjes om te mailen, maar dat is de excelfile zelf, we willen dus de gegenereerde pdf mailen.
Kan zoiets wel?
Nu willen we eigenlijk dat VBA deze PDF file ook automatisch gaat e-mailen.
Er bestaan scriptjes om te mailen, maar dat is de excelfile zelf, we willen dus de gegenereerde pdf mailen.
Kan zoiets wel?
PHP:
Sub OpslaanAlsPdf()
'met controle
Dim Pad As String
Dim Bestandsnaam As String
Pad = ActiveWorkbook.Path + "\"
Dim Sysdate
Sysdate = Format(Date, "yyyy/mm/dd")
Bestandsnaam = "WMA_" & Sysdate & "_" & Replace(Replace(Replace(Replace(Range("C2") & "_snr_" & Range("C4").Value, "\", "-"), "/", "-"), ",", "-"), "&", "-")
Bestandsnaam = Join(Split(Bestandsnaam, ":"))
If Not Dir(Pad & Bestandsnaam & ".pdf") = Empty Then
If MsgBox("Het bestand " & Bestandsnaam & " bestaat al in " & vbCrLf & Pad & vbCrLf & "Wil je dit bestand overschrijven?", vbExclamation + vbOKCancel, "LET OP !! Bestand bestaat al!") = vbCancel Then Exit Sub
End If
If Range("C2") = Empty Then
If MsgBox("Er is geen postcode + nr ingevuld. Hierdoor kan dit bestand niet worden opgeslagen.", vbExclamation + vbCritical, "LET OP !! Bestand kan niet worden opgeslagen!") = vbOK Then Exit Sub
End If
If Range("C4") = Empty Then
If MsgBox("Er is geen serienummer ingevuld. Hierdoor kan dit bestand niet worden opgeslagen.", vbExclamation + vbCritical, "LET OP !! Bestand kan niet worden opgeslagen!") = vbOK Then Exit Sub
End If
If Range("W25") = Empty Then
If MsgBox("Er is nog geen conclusie ingevuld. Maak een keuze tussen 'A', 'B', 'C' of 'D' en kies dan opnieuw Opslaan (PDF).", vbExclamation + vbCritical, "LET OP !! Bestand kan niet worden opgeslagen!") = vbOK Then Exit Sub
Else
With Sheets("Blad1")
.PageSetup.Orientation = xlLandscape
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Pad + Bestandsnaam, Quality:=xlQualityMinimum, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End With
End If
End Sub