我有三个word文档文件,我想用Now()日期重命名它们。三个文件如下
1. EMEA.doc --改名-> EMEA 083117.doc -> EMEA 082317.PDF
2. CEEMEA.doc --改名-> CEEMEA 083117.doc -> CEEMEA 082317.PDF
3. LATAM.doc --改名-> LATAM 083117.doc --> LATAM 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发布于 2017-10-06 09:22:03
为三个文件创建UserForm,并在PDF_Click中复制代码(如下所示)。
代码将逐一打开所有三个文件,并使用SAVEAS进行Now() date操作,并为使用For loop标记的文件创建PDF。
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这个答案对于批评家来说是可以改进的。
发布于 2017-08-23 08:07:12
总方向:
备注:您从来没有真正“转换”一个字文件,只保存一个额外的(PDF)文件。为了使它看起来像一个“转换”,您需要将PDF保存在同一个位置,并删除原始的word文件。
如果您需要帮助解决程序中的特定问题,请使用所讨论的代码行更新您的帖子,并说明错误/错误行为、期望的行为以及到目前为止您试图解决的问题。
https://stackoverflow.com/questions/45833009
复制相似问题