Results 1 to 2 of 2

Thread: Get Images From Word Document And Rename And Save To A Folder

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Get Images From Word Document And Rename And Save To A Folder

    Hi,
    I have a word document with images in it and using microsoft word VBA I want to go through the document, name each image, and move these images to a folder. I have tried inlineobjects, but this does not include each image on my page. The only way I have been able to extract them is by saving the doc as a webpage, but I am not able to delete or rename the images this way.
    Please help.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Try this
    Code:
    Sub GetPicturesFromWordDocument()
    
        Dim strFile As String
        Dim strFileType As String
        Dim strPath As String
        Dim lngLoop As Long
        Dim strOriginalFile As String
        Dim strDocumentName As String
        strOriginalFile = ActiveDocument.FullName
        strDocumentName = Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1)
        strPath = ActiveDocument.Path
        ActiveDocument.SaveAs strPath & "\" & strDocumentName, wdFormatHTML, , , , , True
        strFileType = "*.png;*.jpeg;*.jpg;*.bmp" 'Split with semi-colon if you want to specify more file types.
         
        MkDir strPath & "\MovedToHere"
        For lngLoop = LBound(Split(strFileType, ";")) To UBound(Split(strFileType, ";"))
            strFile = Dir(strPath & "\" & strDocumentName & "_files\" & Split(strFileType, ";")(lngLoop))
            Do While strFile <> ""
                Name strPath & "\" & strDocumentName & "_files\" & strFile As strPath & "\MovedToHere\" & "New " & strFile
                strFile = Dir
            Loop
        Next lngLoop
        ActiveDocument.Close 0
        Documents.Open strOriginalFile
        Kill strPath & "\" & strDocumentName & ".htm*"
        Kill strPath & "\" & strDocumentName & "_files\*.*"
        RmDir strPath & "\" & strDocumentName & "_files"
        strFile = vbNullString
        strFileType = vbNullString
        strPath = vbNullString
        lngLoop = Empty
         
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. Save Worksheets As New File To Specific Folder
    By k0st4din in forum Excel Help
    Replies: 18
    Last Post: 06-08-2013, 04:24 PM
  2. Replies: 2
    Last Post: 04-17-2013, 11:53 PM
  3. Save Processed Files Into Different Another Folder
    By DARSHANKmandya in forum Excel Help
    Replies: 1
    Last Post: 03-22-2013, 07:10 PM
  4. List File name in folder to excel with images
    By Ryan_Bernal in forum Excel Help
    Replies: 2
    Last Post: 01-15-2013, 11:37 AM
  5. Send Outlook Email With Word Document
    By Murali K in forum Excel Help
    Replies: 2
    Last Post: 06-27-2012, 08:42 PM

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
  •