Results 1 to 10 of 24

Thread: Get Pictures from Word Documents in All Sub Folders

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Hi,
    Quote Originally Posted by prkhan56 View Post

    Thanks a lot for taking time and submitting the test code.
    It pops up with a message box saying you don't have any files to be killed and when pressed Ok it highlights the same line as mentioned in my previous post.
    ....
    As you probably realise, the purpose of the test coding is to see if VBA thinks it sees a file of the type which the erroring code line tries to kill ( delete ). The test coding does not appear to see any files of that type, Hence, as we know, the Kill Statement ( https://bettersolutions.com/vba/func...-statement.htm ) will error.




    Quote Originally Posted by prkhan56 View Post
    ...The sample file is attached herewith for you to test..
    Thanks for the file.
    I think I see now some of the information which I was missing: I wrote a few times already that I could not understand why you save the active file with this code line
    ActiveDocument.SaveAs strPath & "" & strDocumentName, wdFormatHTML, , , , , True
    If you do that code line for when the active file is a very simple file, for example a Word file , MyFile.doc , with just some simple plain text in it, then you get a simple file saved which simply has its name changed to MyFile.htm. At least that was my experience so far: I have only limited experience with these sort of Word / html things
    Now I see something for the first time:
    I see now that when you do that code line for when the active file is a Word file which contains images, like your 2. KEEP DUPLICATE RECORDS.docx , then you no longer get a simple file saved which simply has its name changed to 2. KEEP DUPLICATE RECORDS.htm
    Instead you get a lot of other stuff, including some image files.

    So that explains some of the mystery. If you were not aware that this happens, then I am puzzled that you have got this far, and am puzzled that you ever got the macro to work…
    If you were aware of this, then you should have told me. If you ask for help on a forum, you should always gives as much information as possible: It’s best to assume the person trying to help you has no idea of what you are doing or wanting to do or how you are attempting to do it.

    So , what’s going on….
    I lack the experience with these Word and Word VBA issues.
    But my initial uneducated guess is that Word will produce different file types when you save with the .htm extension type and that possibly exactly what you get will depend on many factors. This might explain why you get varying results. I don’t really have the experience to help here. I am seeing this phenomena for the first time.




    Quote Originally Posted by prkhan56 View Post
    ... in duplicates one in .png and one in .jpg format - this is also strange behaviour!), ....
    I think I may have heard of that phenomena before, but I can’t recall where and when. This is possibly coming back to my previous point above, that….. my initial uneducated guess is that Word will produce different file types when you save with the .htm extension type and that possibly exactly what you get will depend on many factors. This might explain why you get varying results.





    So I am working in Word 2007, and when I run the macro with 2. KEEP DUPLICATE RECORDS.docx active, then the code line ActiveDocument.SaveAs strPath & "" & strDocumentName, wdFormatHTML, , , , , True produces this
    2_ KEEP DUPLICATE RECORDS_docx gices these files when saved as _htm.JPG2_ KEEP DUPLICATE RECORDS_docx gives these files when saved as _htm.JPG


    Running the complete macro will ( before it errors ) produce this, which I expect is similar to what you have seen:
    2_ KEEP DUPLICATE RECORDS_docx gives these files.JPG 2_ KEEP DUPLICATE RECORDS_docx gives these files.JPG 2_ KEEP DUPLICATE RECORDS_docx gives these files when saved as _htm.JPG


    Those last 3 screen shots are the same as the previous 2 except that we have also made the directory , MovedToHere , using this code line __ If Dir(strPath & "\MovedToHere", vbDirectory) = "" Then MkDir strPath & "\MovedToHere"




    So it all makes sense to me, now. I see where the problem is coming from.
    _ No file is produced with the .htm extension, Hence the macro will error if no other files of that type are present.
    _ Nothing gets moved to the directory , MovedToHere , because you are looking in the wrong place for those files: The files are in that strange named folder 2-files. ( My Excel is German so Files is translated to Dateien )

    I think I probably could re write the macro so that it does what you want, at least here in my Word 2007 version. But it might not work in your system if the code line ActiveDocument.SaveAs strPath & "" & strDocumentName, wdFormatHTML, , , , , True produces slightly different files

    I do have many different versions of Word and many different computers. I could probably write a macro and check that it works in all systems. But that would be a lot of work for me which I don’t have the time to do all that just now.
    The solution would probably involve looking at all sub folders to make sure we find any files anywhere. Once again this increases the complexity and so increases the work needed.





    You might be best advised to try at one of the other forums.
    There are lots more people there and you might be lucky to find someone that has tried to do exactly what you are doing , had similar problems, and has an efficient solution already.
    I could probably come up with a new solution, but it may not be the best.
    ( If you get the problem solved at another forum , it would be helpful to tell us about it, for the benefit of anyone else seeing this Thread in the future ).

    Otherwise I will take another look at this in a few days when I have some free time


    I would also advise that you take some time to understand the current macro, and possibly add your own explaining 'comment notes .

    Alan
    Last edited by DocAElstein; 09-03-2021 at 04:00 PM.

  2. #2
    Junior Member
    Join Date
    Aug 2021
    Posts
    13
    Rep Power
    0
    Dear Alan,
    Thanks for all the explanation and time to have look at the macro.
    The code I posted was from the Excel group on this forum only and that is the reason I posted it initially on the Word and then later on the Excel Forum.

    I did a search on Google before posting the problem on this forum and unfortunately could not find a suitable solution.
    This was the one which was suiting my requirement, which is not working now.

    I would rather wait for your free time and see what you come up with.

    Thanks once again.

Similar Threads

  1. Replies: 1
    Last Post: 08-26-2021, 11:42 AM
  2. Replies: 3
    Last Post: 07-09-2020, 02:17 AM
  3. Replies: 7
    Last Post: 08-24-2015, 10:58 PM
  4. Replies: 9
    Last Post: 07-26-2013, 02:34 PM
  5. Replies: 1
    Last Post: 10-16-2012, 01:53 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
  •