打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Excel 利用Word 2010自带的保存PDF功能批量转换doc为PDF
2012-11-27 20:37

  1. Option Explicit

  2. Dim FileAddress As String

  3. Dim TargetAddress As String

  4. Sub Main()

  5. Application.ScreenUpdating = False

  6. Dim tempStr

  7. FileAddress = 'C:\Userfile '

  8. TargetAddress = 'C:\Userfile \PDF\'

  9. tempStr = Dir(FileAddress & '\*.docx')

  10. While tempStr <> ''

  11. Documents.Open FileAddress & '\' & tempStr

  12. SaveAsPdfFile

  13. Documents(tempStr).Close False

  14. tempStr = Dir

  15. Wend

  16. Application.ScreenUpdating = True

  17. End Sub

  18. Sub SaveAsPdfFile()

  19. Dim strDocName, strPdfName As String

  20. Dim intPos As Integer

  21. ' Find position of extension in file name

  22. strDocName = ActiveDocument.Name

  23. intPos = InStrRev(strDocName, '.')

  24. If intPos = 0 Then

  25. ' If the document has not yet been saved

  26. ' Ask the user to provide a file name

  27. strDocName = InputBox('Please enter the name ' & _

  28. 'of your document.')

  29. Else

  30. ' Strip off extension and add '.txt' extension

  31. strDocName = Left(strDocName, intPos - 1)

  32. strPdfName = strDocName & '.pdf'

  33. End If

  34. ' Save file with new extension

  35. ActiveDocument.SaveAs2 FileName:=TargetAddress & strPdfName, _

  36. FileFormat:=wdFormatPDF

  37.   End Sub


上面是一个利用Word 2010自带的保存PDF功能批量转换doc为PDF的例子(见下),可以将一个目录中的所有doc全部转换为PDF并保存在另外一个目录下。
有没有高人可以设计一个类似下面图片中的窗体,这样可以比较方便地选择doc和PDF的所在目录,而不用每次修改VBA代码。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Doc11.pdf
PDF转DOC
姓名书籍
2013年驾考科目一题集 PDF+DOC
投资理财资料集锦(2)
WORD文档DOC转PDF
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服