我有一个 Word 2010 模板。我在顶部有一个按钮,可以自动将 Word 文档保存为具有(几乎)正确名称的 pdf,在正确的目录中,然后打开文档。
我还有一个下拉表单字段来选择月份。
按钮的代码:
Private Sub CommandButton1_Click()
Convert_PDF
End Sub
Sub Convert_PDF()
Dim desktoploc As String
Dim filename As String
Dim date As String
Dim user As String
Dim mypath As String
desktoploc = CreateObject("WScript.Shell").SpecialFolders("Desktop")
filename = "Installs Team Metrics"
user = VBA.Environ("USERNAME")
mypath = desktoploc & "\Metrics\" & filename & " - " & date & " - " & user
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
mypath, _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End Sub
这会将文件输出到 C:\Users[username]\Desktop\Metrics\Installs Team Metrics - [Month] - [username].pdf
如何将下拉框中选择的内容获取到字符串“日期”。