Visual Basic for Word, Infinite loop when pasting image

Asked

Viewed 18 times

0

Hello, first question here. I have very basic knowledge of VB.

Need for each image of a Word document to perform the following task 1.Dimensionar 2.Insert Paragraph 1 3.Paste(pasted element will be in "crtl+c") 4.Next image

I was able to make a code that works, but my element that will be pasted also has an image (image+text) and because of that my code will loop pasting behind glue.

I need to somehow make the pasted image be ignored and the code go to the next existing image.

Down with the code I got:

  Dim oInShape As Word.InlineShape  
  For Each oInShape In ActiveDocument.InlineShapes
    oInShape.LockAspectRatio = msoFalse    
    'Ajusta largura da imagem'
    oInShape.Width = 312  
    'Ajusta altura da imagem'
    oInShape.Height = 234    
    oInShape.LockAspectRatio = msoTrue
  Next oInShape    
  For Each oInShape In ActiveDocument.InlineShapes      
    Selection.TypeParagraph
    Selection.PasteAndFormat (wdFormatOriginalFormatting)    
  Next oInShape
End Sub```

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.