Consulting

Results 1 to 2 of 2

Thread: Copy and paste images from excel to word with VBA

  1. #1

    Copy and paste images from excel to word with VBA

    Goodmorning

    I'm writing a macro to copy images from an Excel sheet to a specific Word file (in my case, "Pippo2").
    This macro look if the word file is open and, if not, the macro do it.
    My problem is that when I paste more than one image, the new one overwrites the previous, but I would like to have all the images one under the other. Someone could help me?

    Here my code:

    Dim xPic As Picture
    Dim WordApp As Object



    Sub sposta()


    For Each xPic In ActiveSheet.Pictures
    xPic.Select
    Selection.Copy


    On Error Resume Next
    Set WordApp = GetObject(, "Word.application") 'gives error 429 if Word is not open
    If Err = 429 Then
    Set WordApp = CreateObject("Word.application") 'creates a Word application
    Err.Clear
    End If

    fileword = "C:\Users\szuttion\Desktop\Pippo2.docx"
    WordApp.Visible = True
    If fileword = "False" Then Exit Sub
    With WordApp.Documents.Open(fileword)
    .Content.InsertAfter vbCr
    .Range.Paste



    End With


    Set WordApp = Nothing

    Next

    End Sub


    PS: sorry for my english, it's not my motherlanguage

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    E basta cosí:

    Sub M_snb()
      With GetObject("C:\Users\szuttion\Desktop\Pippo2.docx")
        .Windows(1).Visible = True
        For Each it In Sheet1.Pictures
          it.CopyPicture
          .Paragraphs.Last.Range.Paste
          .Content.InsertAfter String(5, vbCr)
        Next
     End With
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •