| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3394 人关注过本帖
标题:求教:Word打印PDF设置OutputFileName后PDF文件损坏
只看楼主 加入收藏
xia95
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2021-6-26
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
求教:Word打印PDF设置OutputFileName后PDF文件损坏
程序代码:
Sub 宏1()
'
' 宏1 宏
'
'
    Dim path As String
    path = "F:\一户一档\"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.getfolder(path)
    Set sfs = f.SubFolders
    For Each sf In sfs
        ChangeFileOpenDirectory (sf)
        Documents.Open FileName:="01不动产登记申请书.doc", ConfirmConversions:=False, _
        ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
        Application.PrintOut Background:=False, Append:=False, Range:=wdPrintAllDocument, OutputFileName:=sf & "\01不动产登记申请书.pdf", Copies:=1, PageType:=wdPrintAllPages, PrintTOFile:=True, Collate:=True, ManualDuplexPrint:=False
        ActiveWindow.Close
        Documents.Open FileName:="03不动产权籍调查表.doc", ConfirmConversions:=False, _
        ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
        Application.PrintOut Background:=False, Append:=False, Range:=wdPrintAllDocument, OutputFileName:=sf & "\03不动产权籍调查表.pdf", Copies:=1, PageType:=wdPrintAllPages, PrintTOFile:=True, Collate:=True, ManualDuplexPrint:=False
        ActiveWindow.Close
    Next
End Sub

搜索更多相关主题的帖子:  path PDF False Word 
2021-06-26 11:25
xia95
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2021-6-26
收藏
得分:0 
回复 楼主 xia95
图片附件: 游客没有浏览图片的权限,请 登录注册
2021-06-26 11:26
xia95
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2021-6-26
收藏
得分:0 
回复 楼主 xia95
把OutputFileName:=sf & "\01不动产登记申请书.pdf", PrintTOFile:=True去掉可以正常打印,不过每一个都要手动选择路径保存
2021-06-26 12:03
厨师王德榜
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:199
帖 子:995
专家分:4966
注 册:2013-2-16
收藏
得分:20 
可以给你参考一下我的代码:
遍历某文件夹,并将其下所有的 Word文档另存为PDF
程序代码:
Sub Traver_Folder_Save2PDF()
'遍历某文件夹及其下一级子文件夹下文件(非递归方法)
'并将所有Word文档另存为PDF
'Code by:厨师王德榜  2021.6.28
    Dim cPath As String, subPath As String, subFile
    cPath = "c:\XIDE\Plugins\"
    cPath = IIf(Right(cPath, 1) <> "\", cPath & "\", cPath)
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set Folder0 = FSO.getfolder(cPath)
    '遍历自身拥有的文件
    If Folder0.Files.Count > 0 Then
        For Each subFile In Folder0.Files
            subFile = (subFile.Name)
            If InStr(1, LCase(subFile), ".doc", vbTextCompare) > 0 Then Save_as_PDF cPath, subFile
        Next subFile
    End If
    
    If Folder0.subfolders.Count > 0 Then
    Set sfs = Folder0.subfolders
    For Each sf In sfs  '遍历下一级拥有的文件
        subPath = sf.path
        subPath = IIf(Right(subPath, 1) <> "\", subPath & "\", subPath)
      If sf.Files.Count > 0 Then

        For Each subFile In sf.Files
            subFile = (subFile.Name)
            If InStr(1, LCase(subFile), ".doc", vbTextCompare) > 0 Then Save_as_PDF subPath, subFile
        Next subFile

      End If
    Next
    End If
End Sub

Public Sub Save_as_PDF(ByVal paraPath As String, ByVal paraFile As String)
Dim cFout As String, ii As Integer
Dim oleDoc As Object
ii = InStr(1, LCase(paraFile), ".doc", vbTextCompare)
cFout = Left(paraFile, ii - 1) + ".pdf"
cFout = paraPath & cFout
If Len(Dir(paraPath)) > 0 Then
    ChangeFileOpenDirectory (paraPath)
    
   If Len(Dir(paraPath & paraFile)) > 0 Then
     Set oleDoc = Documents.Open(FileName:=paraFile, _
        ConfirmConversions:=False, _
        ReadOnly:=False, _
        AddToRecentFiles:=False, _
        PasswordDocument:="", _
        PasswordTemplate:="", _
        Revert:=False, _
        WritePasswordDocument:="", _
        WritePasswordTemplate:="", _
        Format:=wdOpenFormatAuto, _
        XMLTransform:="")
        
      oleDoc.Activate
      If Len(Dir(cFout)) > 0 Then Kill cFout
    
    oleDoc.ExportAsFixedFormat _
        OutputFileName:=cFout, _
        ExportFormat:=wdExportFormatPDF, _
        OpenAfterExport:=False, _
        OptimizeFor:= _
        wdExportOptimizeForPrint, _
        Range:=wdExportAllDocument, _
        From:=1, To:=1, _
        Item:=wdExportDocumentContent, _
        IncludeDocProps:=True, _
        KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, _
        DocStructureTags:=True, _
        BitmapMissingFonts:=True, _
        UseISO19005_1:=False
        
        oleDoc.Saved = True
        oleDoc.Close
        Set oleDoc = Nothing
    End If
End If
End Sub
2021-06-28 10:09
快速回复:求教:Word打印PDF设置OutputFileName后PDF文件损坏
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.140637 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved