回复 2# holley
vbs..可以,,
- ' Word转PPT的VBScript示例
- Option Explicit
- Dim wordApp, pptApp
- Dim wordDoc, pptPresentation
- Dim wordParagraphs, slide
- Dim i, slideCount
- On Error Resume Next
- ' 创建Word应用程序对象
- Set wordApp = CreateObject("Word.Application")
- If Err.Number <> 0 Then
- MsgBox "无法创建Word应用程序对象。请确保已安装Microsoft Word。"
- WScript.Quit
- End If
- On Error GoTo 0
- wordApp.Visible = False
- ' 打开Word文档
- Set wordDoc = wordApp.Documents.Open("C:\你的文档路径\文档.docx")
- ' 创建PowerPoint应用程序对象
- On Error Resume Next
- Set pptApp = CreateObject("PowerPoint.Application")
- If Err.Number <> 0 Then
- MsgBox "无法创建PowerPoint应用程序对象。请确保已安装Microsoft PowerPoint。"
- wordApp.Quit
- WScript.Quit
- End If
- On Error GoTo 0
- pptApp.Visible = True
- ' 创建新的PPT演示文稿
- Set pptPresentation = pptApp.Presentations.Add
- ' 获取Word文档中的所有段落
- Set wordParagraphs = wordDoc.Paragraphs
- ' 遍历每个段落并添加到PPT
- For i = 1 To wordParagraphs.Count
- If Trim(wordParagraphs(i).Range.Text) <> "" Then
- ' 添加新幻灯片
- If i = 1 Then
- Set slide = pptPresentation.Slides.Add(1, 1) ' 标题幻灯片
- slide.Shapes(1).TextFrame.TextRange.Text = wordParagraphs(i).Range.Text
- Else
- Set slide = pptPresentation.Slides.Add(i, 2) ' 标题和内容幻灯片
- slide.Shapes(1).TextFrame.TextRange.Text = "Slide " & i
- slide.Shapes(2).TextFrame.TextRange.Text = wordParagraphs(i).Range.Text
- End If
- End If
- Next
- ' 保存PPT
- pptPresentation.SaveAs "C:\你的文档路径\输出.pptx"
- ' 清理对象
- wordDoc.Close
- wordApp.Quit
- pptApp.Quit
- Set slide = Nothing
- Set pptPresentation = Nothing
- Set pptApp = Nothing
- Set wordParagraphs = Nothing
- Set wordDoc = Nothing
- Set wordApp = Nothing
- MsgBox "转换完成!"
复制代码 |