Replace the function with all (!) code below and try again. What happens?
Andreas.
Public Function generatePDFReport(ReportType As String, sheet As Worksheet, sDate As String) As String
Dim filePath As String
Dim shipName
Dim Where As Range
sDate = Replace(sDate, "\", "_")
shipName = ActiveWorkbook.Worksheets("Voyage info").Range("MV").Value
filePath = CreateObject("WScript.Shell").specialfolders("MyDocuments")
filePath = filePath & "\" & shipName & "_" & ReportType & "_" & Replace(sDate, "-", "_") & ".pdf"
filePath = ValidFileName(filePath)
If ReportType = "Pool Declaration Report" Then
'sheet.Activate
'sheet.Range("B1:F30").Select
Set Where = sheet.Range("B1:F30")
Else
'sheet.Activate
'sheet.Range("B8:F44").Select
Set Where = sheet.Range("B8:F44")
End If
'Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
filePath, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Where.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filePath
generatePDFReport = filePath
End Function
Private Function ValidFileName(ByVal FName As String, _
Optional ByVal ReplaceChar As String = "") As String
'Return a filename without invalid chars
'Avoid CON, PRN, AUX, NUL, COM1 to COM9, LPT1 to LPT9 as filename
Const InvalidChars = "\/:*?""<>|"
Dim i As Integer, p As Long
Dim Digit As String
For i = 1 To Len(InvalidChars)
Digit = Mid$(InvalidChars, i, 1)
p = InStr(FName, Digit)
Do While p > 0
Mid$(FName, p, 1) = vbNullChar
p = InStr(FName, Digit)
Loop
Next
For i = 1 To 31
Digit = Chr$(i)
p = InStr(FName, Digit)
Do While p > 0
Mid$(FName, p, 1) = vbNullChar
p = InStr(FName, Digit)
Loop
Next
ValidFileName = Replace(FName, vbNullChar, ReplaceChar)
End Function