1

我在使用 VBA 让我的图片在 Word 2003 中的文本后面换行时遇到问题。我可以很好地使用所有其他包装选项,但是当我尝试使用 wdWrapBehind 时,出现以下错误。

“编译错误:未定义变量”

我通过谷歌到处打猎,但没有运气。

代码:

      Dim shape1 As shape
      Dim imagePath1 As String

      imagePath1 = "C:\image.jpg"

      Set shape1 = ActiveDocument.Shapes.AddPicture(imagePath1)

      With shape1
        .ScaleHeight 1, msoTrue
        .ScaleWidth 1, msoCTrue
        .LockAspectRatio = msoTrue
        .WrapFormat.Type = wdWrapBehind
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        .Left = InchesToPoints(0.433)
        .Top = InchesToPoints(0.413)
      End With

任何帮助表示赞赏!

干杯,迈克尔

4

1 回答 1

1

通过添加这 4 行而不是 wdWrapBehind 设法使其工作。

        .WrapFormat.AllowOverlap = True
        .WrapFormat.Side = wdWrapBoth
        .WrapFormat.Type = 3
        .ZOrder 5

完整代码:

    Dim shape1 As shape         
    Dim imagePath1 As String            
    imagePath1 = "C:\image.jpg"            
    Set shape1 = ActiveDocument.Shapes.AddPicture(imagePath1)   

    With shape1
        .ScaleHeight 1, msoTrue
        .ScaleWidth 1, msoCTrue
        .WrapFormat.AllowOverlap = True
        .WrapFormat.Side = wdWrapBoth
        .LockAspectRatio = msoTrue
        .WrapFormat.Type = 3
        .ZOrder 5
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        .Left = InchesToPoints(6.889)
        .Top = InchesToPoints(0.374)
    End With
于 2012-10-02T21:41:02.450 回答