如何使用后期绑定vba将上次粘贴的特殊图片的wrapformat.type从word中的excel更改为wdWrapTopBottom

问题描述

现在的问题是:所有图片都粘贴为wrap.format.type = wdInLine 另一个人需要稍后在他的模板中添加单词 doc : 插入 - 对象 - 文件中的文本 然后所有图片都没有正确显示。它们被包裹在书签中。

This is the wrapped picture and not fully displayed

如果我为每张图片手动将 wdInline 更改为 wdWrapTopBottom,这又可以了。

这是我的代码

    Sub excelToWord()
            Dim xlApp As Object
            Dim xlDoc As Object
            Dim wdApp As Object
            Dim wdDoc As Object

   'late binding needs constants
    Const wdOutlineView = 2
    Const wdPrintView = 3
    Const wdnormalView = 1
    Const wdSeekCurrentPageHeader = 9
    Const wdSeekCurrentPageFooter = 10
    Const wdFieldEmpty = -1
    Const wdSeekMainDocument = 0
    Const wdalignParagraphCenter = 1
    Const wdalignParagraphRight = 2
    Const wdGoToBookmark = -1
    Const wdGoToheading = 11
    Const wdPageBreak = 7
    Const wdGoToNext = 2
    Const wdGoToPage = 1
    Const wdCollapseEnd = 0
    Const wdCollapseStart = 1
    Const wdPasteMetafilePicture = 3
    Const wdPasteEnhancedMetafile = 9
    Const wdPasteShape = 8
    Const wdFloatOverText = 1
    Const wdInlineshapePicture = 3
    Const wdPaneNone = 0
    
        Set xlApp = Getobject(,"Excel.Application")
        Set wdApp = Getobject(,"Word.Application")
        wdApp.Visible = True

        Set xlDoc = ActiveWorkbook
            
repeat: 'normally for each .. in ..
          xlDoc.Activate
          'I make some selection I would like to paste as picture in word.
          Range("A1:B2").Select 'dummy in this case
          Selection.copyPicture Appearance:=xlScreen,Format:=xlPicture
          lWidth = Selection.Width
          lHeight = Selection.Height
          
          
          'with a picker I pick a word file 'myFile'
        Set wdDoc = wdApp.Documents.Open(myFile)
        wdDoc.Activate
          
         With wdApp
          .Visible = True
          If Page = 0 Then
          .Selection.Goto what:=wdGoToBookmark,Name:="input"
          .Selection.Collapse Direction:=wdCollapseEnd
          'only first time insert Break
          .Selection.InsertBreak (wdPageBreak)
          .Selection.InsertLine
          .Selection.InsertAfter Chr(13)
          .Selection.TypeText Text:="  Excel Input"
    End If
          .Selection.InsertLine
          .Selection.InsertAfter Chr(13)
          .Cursor.MoveDown Unit:=wdLine,Count:=1
          .Selection.TypeText Text:=Chr(13)
          .Cursor.MoveDown Unit:=wdLine,Count:=1
          .Selection.PasteSpecial Link:=False,displayAsIcon:=False,_
            DataType:=wdPasteEnhancedMetafile,Placement:=wdInline 'Placement:=wdInLine

'The problem Now is from here. All pictures are pasted as wrap.format.type = wdInLine
' another person needs to add the word doc later in his template ( I can not change this template-no access).
' with insert - object - text from file
'and then all pictures are not shown correctly anymore. they are wrapped in the bookmark.
'If I change the wdInline  into wdWrapTopBottom manually this is ok again.

 
'this is what I tried but it does not select the last pasted picture. myPicture is just empty. so no change is made.
    'Selection.MoveLeft Unit:=wdLine,Count:=1,Extend:=wdExtend
    Set myPicture = Selection.Inlineshapes(1)
    Set MyShape = myPicture.ConvertToShape
    With MyShape.Wrapformat
      .Type = wdWrapTopBottom
      .AllowOverlap = False
    End With
    
    End With
    Page = Page + 1
          
    'repeat for next xl copy picture..... etc
GoTo repeat 'normally next...
End Sub

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)