由于有一个小程序,我正在从Excel中打印一些PDF,该程序正在运行,现在不再可用,我不知道为什么。告诉我
错误“ 5”参数或过程调用不正确。
我认为这确实是一个愚蠢的错误,但是我无能为力。
文件名部分不是问题,将其更改为诸如“ bob”之类的基本内容时,我会得到相同的结果
Sub impression_multiple_pdf()
Dim chaine As String
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
If WS.Name <> "Tampon" And WS.Name <> "data" And WS.Name <> "Tableau de
Bord" Then
WS.ExportAsFixedFormat Type:=xlTypePDF,
Filename:=ThisWorkbook.Path & "\Fiches Projet\Fiche Projet " &
clear_name(WS.Range("C3")), Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False,
OpenAfterPublish:=False
End If
Next
ThisWorkbook.Activate
MsgBox "Fiches projet enregistrées dans mes documents"
End Sub
清除名称功能:
Function clear_name(txt)
Dim C
C = Array("<", ">", "?", "[", "]", ":", "*", "\", "/", "|", ".", "#", "€",
",", "§", "@")
'txt = Range("A2")
For n = 0 To UBound(C)
txt = Left(Trim(txt), 128)
txt = Replace(txt, C(n), "")
Next
clear_name = txt
End Function
答案 0 :(得分:1)
确保clear_name(WS.Range("C3"))
不为空。
另外,请确保ThisWorkbook.Path
返回一个值,这意味着您的工作簿至少需要保存一次。并确保您的路径存在\Fiches Projet\Fiche Projet
,否则它将失败。
Sub impression_multiple_pdf()
Dim chaine As String
Dim WS As Worksheet
Dim Filename As String
For Each WS In ThisWorkbook.Worksheets
If WS.Name <> "Tampon" And WS.Name <> "data" And WS.Name <> "Tableau de Bord" Then
Filename = clear_name(WS.Range("C3"))
If Filename <> "" Then
WS.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "\Fiches Projet\Fiche Projet " & Filename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Else
MsgBox "Filename in '" & WS.Name & "' was empty"
End If
End If
Next WS
ThisWorkbook.Activate
MsgBox "Fiches projet enregistrées dans mes documents"
End Sub
如果这不能帮助使用
Debug.Print ThisWorkbook.Path & "\Fiches Projet\Fiche Projet " & Filename
在Filename = clear_name(WS.Range("C3"))
行之后,告诉打印在立即窗口中的结果。
答案 1 :(得分:0)
尝试编辑此部分
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\Fiches Projet\Fiche Projet " & clear_name(ws.Range("C3")), Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False