|
* 楼主,如果这些代码是你写的,我就太佩服你了!受益匪浅!
* 楼上 张老师 和 戴老师 都说明白了,确实没啥大改动的,仅差一点点,下面的代码运行完美(桌面上已自动生成PDF文档):
- Private Sub CommandButton1_Click()
- Dim doc As Document
- Set doc = ThisDocument
- doc.FormFields("文字1").Result = TextBox1
- doc.FormFields("文字2").Result = TextBox2
- doc.FormFields("文字3").Result = TextBox3
- doc.FormFields("文字4").Result = TextBox4
- doc.FormFields("文字5").Result = TextBox5
- doc.FormFields("文字6").Result = TextBox6
- End Sub
- Private Sub CommandButton2_Click()
- Dim oDoc As Document
- Set oDoc = Word.ActiveDocument
- Dim oRng As Range
- Set oRng = oDoc.Content
- Dim rg As String
- rg = TextBox7.Value
-
- Dim sPath As String
- '默认存储路径,当前用户桌面,注释掉的是当前文档路径
- sPath = Environ("userprofile") & "\Desktop" 'Word.ActiveDocument.Path & ""
- oDoc.ExportAsFixedFormat OutputFileName:=(sPath & "" & "售后服务确认单 - " & rg & ".pdf"), _
- ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
- wdExportOptimizeForPrint, Range:=wdExportFromTo, From:=1, To:=oDoc.Range.Information(wdNumberOfPagesInDocument), _
- Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
- CreateBookmarks:=wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
- BitmapMissingFonts:=True
- MsgBox "PDF文档已保存!", 0 + 48
- End Sub
复制代码 |
|