Textframe2.copy方法给出错误并且宏停止工作

时间:2017-12-11 14:37:30

标签: vba powerpoint powerpoint-vba

我有一个工作宏来将PPT表转换为单个文本框。这个宏现在突然停止工作,任何人都可以帮助它恢复工作。这最初是由PPTFAQ的MVP Shyam Pillai提出的。 Older post, External code link

现在我得到的错误是

  

'TextFrame2'的方法'复制'失败

Error message screenshot

Sub OverlayCellText()

Dim I As Integer
Dim J As Integer
Dim TableShp As Shape
Dim Shp As Shape
Dim Tbl As Table
Dim txtBox As Shape

Set TableShp = ActiveWindow.Selection.ShapeRange(1)

If TableShp.Type = msoTable Or TableShp.HasTable Then
Set Tbl = TableShp.Table

For I = 1 To Tbl.Rows.Count
    For J = 1 To Tbl.Columns.Count

        Set Shp = Tbl.Cell(I, J).Shape

        Set txtBox = ActiveWindow.Selection.SlideRange(1).Shapes.AddTextbox(Shp.TextFrame2.Orientation, _
                Shp.Left, _
                Shp.Top, _
                Shp.Width, _
                Shp.Height)

        If Shp.TextFrame2.HasText Then
            Shp.TextFrame2.TextRange.Copy

            txtBox.TextFrame2.AutoSize = Shp.TextFrame2.AutoSize
            txtBox.TextFrame2.HorizontalAnchor = Shp.TextFrame2.HorizontalAnchor
            txtBox.TextFrame2.MarginBottom = Shp.TextFrame2.MarginBottom
            txtBox.TextFrame2.MarginLeft = Shp.TextFrame2.MarginLeft
            txtBox.TextFrame2.MarginRight = Shp.TextFrame2.MarginRight
            txtBox.TextFrame2.MarginTop = Shp.TextFrame2.MarginTop

            txtBox.TextFrame2.TextRange.Paste

        End If
    Next
Next
Else
MsgBox "Please select a table shape and then run this macro.", vbExclamation
End If
End Sub

0 个答案:

没有答案