需要将PowerPoint幻灯片复制到Word中的表格

时间:2019-06-04 04:13:28

标签: powerpoint-vba

我想将所有幻灯片和幻灯片注释从PowerPoint复制到Word文档的表格中-表格的第1列将具有幻灯片的图片,第2列将具有注释文本。 (这模拟了PPT的“创建讲义”功能,但使我可以更好地控制Word格式。)

我已经开始着重于复制幻灯片的代码了-但是PPT vba不允许我指定范围功能-因此我在获取将幻灯片粘贴到Col 1中的代码时遇到了问题。

这是我到目前为止所拥有的。这将复制所有幻灯片-但不会放入表格/ col1中。我还没有添加注释的代码-想要先完成幻灯片。

    Sub CopyToWord()

    Dim WdApp As Object
    Dim WdDoc As Object
    Dim r As Integer  'used to track table row

    Dim s As Slide

    Dim myTable As Table

    Dim FontName As String
    Dim FontSize As Integer
    Dim FontColor As String


 'create Word Document
 Err.Clear
    On Error Resume Next

 Set WdApp = GetObject(Class:="Word.Application")
   If Err <> 0 Then
        Set WdApp = CreateObject("Word.Application")
   End If


 WdApp.Visible = True
 Set WdDoc = WdApp.Documents.Add


'Create 2 Column Table and set column widths

ActiveDocument.Tables.Add Range:=myRange, NumRows:=1, NumColumns:=2

Selection.Tables(1).Columns(1).SetWidth ColumnWidth:=175, RulerStyle:= _
    wdAdjustNone

Selection.Tables(1).Columns(2).SetWidth ColumnWidth:=380, RulerStyle:= _
    wdAdjustNone


 'copy each slide to table Col 1
 ActiveDocument.Tables(1).Select
 Set myTable = Selection.Tables(1)
 r = 1

 For Each s In ActivePresentation.Slides
        s.Copy
        ActiveDocument.Tables(1).Rows(r).Cells(1).Select
        WdApp.Selection.Paste
        Selection.InsertRowsBelow (1)
        r = r + 1
 Next


'Add Borders

    ActiveDocument.Tables(1).Select
    With Selection.Borders(wdBorderTop)
        .LineStyle = Options.DefaultBorderLineStyle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    With Selection.Borders(wdBorderLeft)
        .LineStyle = Options.DefaultBorderLineStyle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    With Selection.Borders(wdBorderBottom)
        .LineStyle = Options.DefaultBorderLineStyle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    With Selection.Borders(wdBorderRight)
        .LineStyle = Options.DefaultBorderLineStyle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    With Selection.Borders(wdBorderHorizontal)
        .LineStyle = Options.DefaultBorderLineStyle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    With Selection.Borders(wdBorderVertical)
        .LineStyle = Options.DefaultBorderLineStyle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With

End Sub

感谢您的帮助!

0 个答案:

没有答案
相关问题