将多个文件保存并重命名为 PDF 而无需同时询问位置

Saving and renaming multiple files as PDF without asking for location at the same time

我有三个单词的文档文件,我想用 Now() 日期重命名它们。三个文件如

1. EMEA.doc --重命名-> EMEA 083117.doc -转换-> 欧洲、中东和非洲 082317.PDF

2. CEEMEA.doc --重命名-> CEEMEA 083117.doc - convert-> CEEMEA 082317.PDF

3. LATAM.doc --重命名-> LATAM 083117.doc -convert -> 拉丁美洲 082317.PDF

我需要 ExportAsFixedFormat(PDF) 这些 .Doc 文件。以下代码仅针对 ActiveDocument 执行此操作。我想将文件保存在特定位置而不 VBA 询问位置。

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
    "C:\Documents and Settings\Administrator\Desktop\EMEA CEEMEA\LATAM.pdf", 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

大方向:

  1. 您需要告诉程序您要操作哪些文件(例如“all word files in folder x”)
  2. 您似乎已经有了重命名规则(文件名 & " " & 日期),只需遍历所有有问题的文件即可; batch file 可能是 vba 重命名文件
  3. 的一个很好的替代解决方案
  4. (可以在后台完成,不需要实际打开文档)

注意:你实际上从来没有"convert"一个word文件,只保存了一个额外的(PDF)文件。要使其看起来像 "conversion",您需要将 PDF 保存在同一位置并删除原始 word 文件。

如果您需要帮助解决程序中的特定问题,请使用相关代码行更新您的 post 以及 error/wrong 行为的描述、期望的行为和您拥有的内容到目前为止已尝试修复它。

为三个文件创建 UserForm 并将代码(下面给出)复制到 PDF_Click

代码将一一打开所有三个,并使用 Now() 日期执行 SAVEAS 并使用 [= 创建 PDF 用于选中标记的文件14=].

Private Sub PDF_Click()

Dim d As String

Finalize.hide
Dim C As MSForms.Control
For Each C In Me.Controls
    If TypeName(C) = "CheckBox" Then
    If C.Value = True Then
    If C.Caption = "Select All" Then
    Else

VD = "C:\Documents and Settings\Administrator\Desktop\EMEA CEEMEA\"

Documents.Open FileName:=VD & C.Caption & ".doc"

d = Format(Now(), "mmddyy")
f = VD & Ctl.Caption & " " & d
ActiveDocument.SaveAs2 f & ".doc"

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        f & ".pdf", 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

ActiveDocument.Close

    End If
    End If
    End If

Next
End Sub

此答案对批评者开放,待改进。