|
本帖最后由 kevinchan2006 于 2012-11-27 20:38 编辑
- Option Explicit
- Dim FileAddress As String
- Dim TargetAddress As String
- Sub Main()
- Application.ScreenUpdating = False
- Dim tempStr
- FileAddress = "C:\Userfile "
- TargetAddress = "C:\Userfile \PDF"
- tempStr = Dir(FileAddress & "\*.docx")
- While tempStr <> ""
- Documents.Open FileAddress & "" & tempStr
- SaveAsPdfFile
- Documents(tempStr).Close False
- tempStr = Dir
- Wend
- Application.ScreenUpdating = True
- End Sub
- Sub SaveAsPdfFile()
- Dim strDocName, strPdfName As String
- Dim intPos As Integer
- ' Find position of extension in file name
- strDocName = ActiveDocument.Name
- intPos = InStrRev(strDocName, ".")
- If intPos = 0 Then
- ' If the document has not yet been saved
- ' Ask the user to provide a file name
- strDocName = InputBox("Please enter the name " & _
- "of your document.")
- Else
- ' Strip off extension and add ".txt" extension
- strDocName = Left(strDocName, intPos - 1)
- strPdfName = strDocName & ".pdf"
- End If
- ' Save file with new extension
- ActiveDocument.SaveAs2 FileName:=TargetAddress & strPdfName, _
- FileFormat:=wdFormatPDF
- End Sub
复制代码
上面是一个利用Word 2010自带的保存PDF功能批量转换doc为PDF的例子(见下),可以将一个目录中的所有doc全部转换为PDF并保存在另外一个目录下。
有没有高人可以设计一个类似下面图片中的窗体,这样可以比较方便地选择doc和PDF的所在目录,而不用每次修改VBA代码。
|
|