Results 1 to 2 of 2

Thread: Get Pictures from a Word Document ( in All Sub Folders produced?? )

  1. #1
    Junior Member
    Join Date
    Aug 2021
    Posts
    13
    Rep Power
    0

    Get Pictures from a Word Document ( in All Sub Folders produced?? )

    Dear All,

    I am using Office 2013.

    I have a folder with many sub folders having word and excel files.

    Excel file does not have images but the word documents under each sub folder have many images which I would like to move under each respective folders.

    I found this code on the group which used to work but now it is giving run time error '53': File not found and highlights the following:

    Kill strPath & "" & strDocumentName & ".htm*"

    It used to work and move the images to a folder “MovedToHere”.

    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
    I want to fix this code and also amend to run on all the sub folders.
    Can someone fix this issue for me please.
    Thanks in advance

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,422
    Rep Power
    10
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Similar Threads

  1. Get Pictures from Word Documents in All Sub Folders
    By prkhan56 in forum Excel Help
    Replies: 23
    Last Post: 10-06-2021, 01:17 PM
  2. Replies: 0
    Last Post: 02-23-2017, 11:42 PM
  3. Macro To Connect Word Document To Excel Not Working
    By fjeldgaard in forum Word Help
    Replies: 1
    Last Post: 08-29-2014, 08:31 AM
  4. Loop_Find & Copy to word document
    By Excelfun in forum Excel Help
    Replies: 3
    Last Post: 01-14-2014, 10:11 PM
  5. Send Outlook Email With Word Document
    By Murali K in forum Excel Help
    Replies: 2
    Last Post: 06-27-2012, 08:42 PM

Posting Permissions

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