Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Get Pictures from Word Documents in All Sub Folders

  1. #11
    Junior Member
    Join Date
    Aug 2021
    Posts
    13
    Rep Power
    0
    Dear Alan,
    I was testing your macro on different PCs.

    Unfortunately it does not create the folder "MovedToHere"
    I am enclosing two images which is what the macro creates
    1 - Keep Duplicate Records.htm file
    2 - Keep Duplicate Records_files (folder)

    The folder contains the images which is shown in MacroTest2.png attached
    It is similar to what the previous macro was giving.

    I am totally loss at words what to say now.

    I really appreciate all your time and help in this matter.

    Thanks a lot
    Attached Images Attached Images

  2. #12
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Hello

    I have no idea where your problem is.

    I think you will need to step through the macro in Debug mode yourself and follow through yourself to locate where the problem is


    Example: I try the macro again

    This code line
    DocWithImgs.SaveAs FileName:=strPath & "" & strDocumentName & ".htm", FileFormat:=wdFormatHTML
    makes the .htm file and the _____-Files
    https://i.postimg.cc/66ZRRYJK/Made-2...ECORDS-htm.jpg https://i.postimg.cc/J4WXQZMk/Files-are-made.jpg

    This code bit makes the directory MovedToHere
    If Dir(strPath & "\MovedToHere", vbDirectory) = "" Then MkDir strPath & "\MovedToHere"
    https://i.postimg.cc/YSygNPCr/Direct...re-is-made.jpg

    If you step through this code section, you should see it looping and copying files
    Code:
        Do While strFile <> ""   '     The purpose of the Do While __ Loop _ loop is to keep going while you still find files of the extension type currently being looked for.
         Name strPath & "\" & FileFlder & "\" & strFile As strPath & "\MovedToHere\" & "New " & strFile  '   Each of the files you find gets copied to folder, MovedToHere and has its name modified a bit to have the text "New " added at the start, like for example, Filex.png would become New Filex.png
         Let strFile = Dir  '   The use of Dir on its own, without any bracket ( ) stuff tells VBA to look again for the next file of the same type and in the same place that it looked the last time
        Loop ' While strFile <> ""
    As it loops you will see the folder MovedToHere being filled
    https://i.postimg.cc/mrrCH4Rp/Direct...ing-filled.jpg
    https://i.postimg.cc/6pcCqqsG/Direct...ing-filled.jpg
    https://i.postimg.cc/bJDnmRZQ/Direct...ing-filled.jpg
    https://i.postimg.cc/6qCvX5Lq/Direct...ing-filled.jpg
    https://i.postimg.cc/cHpn283P/Direct...ing-filled.jpg

    https://i.postimg.cc/x1nK9HZ2/Direct...ere-filled.jpg




    This code bit
    If Not Dir(strPath & "" & FileFlder & "\*.*") = "" Then Kill strPath & "" & FileFlder & "\*.*"
    empties the ___-Files folder
    https://i.postimg.cc/BQxTWNMp/File-f...les-killed.jpg







    If you do not know how to step through in Debug F8 mode in VBA , then …..
    Get into the vbeditor ( Key Alt+F11 from Excel ) , and click anywhere in the macro
    https://i.postimg.cc/kGrB53fH/get-into-macro.jpg

    Hit key F8


    This will step you through the macro , one line at a time
    https://i.postimg.cc/R0DWjnf4/Steping-through-in-F8.jpg
    https://i.postimg.cc/d1Zhvtmd/Steping-through-in-F8.jpg
    https://i.postimg.cc/fbL32vV8/Steping-through-in-F8.jpg
    https://i.postimg.cc/XYxGkPYZ/Steping-through-in-F8.jpg
    Steping through in F8.JPGSteping through in F8.jpgSteping through in F8.JPGSteping through in F8.JPG



    Etc…

    At each point, you can check if files and folders are being made, filled or killed , etc., as they should be




    Alan
    Last edited by DocAElstein; 09-22-2021 at 03:44 PM.
    A Folk, A Forum, A Fuhrer ….

  3. #13
    Junior Member
    Join Date
    Aug 2021
    Posts
    13
    Rep Power
    0
    Dear Alan,
    I have run the code as per your instruction.
    It creates the folder as per my previous post.
    I am attaching two images herewith.

    The first one is Debug and the second one is Breakpoint.
    The macro comes out at the breakpoint and does not create any folder "MovedToHere".

    Thanks once again for all your time and help.
    Attached Images Attached Images

  4. #14
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Hi
    Quote Originally Posted by prkhan56 View Post
    .....
    The macro comes out at the breakpoint and does not create any folder "MovedToHere"..
    I don't quite understand what you mean by this.

    Do you mean that the macro errors at this line?
    Code:
    Documents(strDocumentName & ".htm").Close



    Where do you have the macro? In which document do you have the macro?
    A Folk, A Forum, A Fuhrer ….

  5. #15
    Junior Member
    Join Date
    Aug 2021
    Posts
    13
    Rep Power
    0
    Hi Alan,
    Yes as per the screen shot I sent to you, the macro comes out on the Breakpoint image.
    It does not create any folder "MovedToHere" and move the images in this folder.
    Hope it is clear now.

    The macro is in the Word File inserted as a Module which is open at the time of running the macro
    Last edited by prkhan56; 09-23-2021 at 12:06 AM. Reason: missed a point

  6. #16
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Hi
    Quote Originally Posted by prkhan56 View Post
    .., the macro comes out ...
    I am still not sure what you meant? What does ..." the macro comes out..." mean? Does the macro stop with an error message. If so , what error message is given?
    _.__________________________

    Quote Originally Posted by prkhan56 View Post
    The macro is in the Word File inserted as a Module which is open at the time of running the macro
    Which Word file? - If it is in the file which is saved as .htm , then when the file is closed, the macro is gone so nothing further will happen.
    _.______________________


    You could try to remove the close and kill lines , ( ' comment them out ), and then see what happens.
    Like this:
    Code:
       '  Documents(strDocumentName & ".htm").Close   ' The purpose of the  Save As    .htm  was to get thee new folder made, that's all, so we can close that file now, and then kill (delete) it
      '  Kill strPath & "\" & strDocumentName & ".htm"    
    A Folk, A Forum, A Fuhrer ….

  7. #17
    Junior Member
    Join Date
    Aug 2021
    Posts
    13
    Rep Power
    0
    Hi Alan,
    I tested the code after commenting the lines as per your instructions.

    The code was copied in the Word file and also in the Normal template.
    Finally it created the 3 folders but before that the following happened.

    When I run the code - see attached images
    1) Message Box popped up - Something went wrong. There is no new folder produced. I press Ok then step 2
    2) Run-time error permission denied - I press Debug then Step 3
    3) It highlights the code (see yellow) - image Error

    So now the MovedToHere folder is created but there are no images in this folder.

    For your information the original Macro used to keep the Word Document open and create the Folder MovedToHere and the images were there in the folders.

    Thanks a lot for all the time and help.
    Attached Images Attached Images
    Last edited by prkhan56; 09-23-2021 at 01:35 PM. Reason: Images were not uploaded

  8. #18
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Hi
    I think the issues are getting far too complicated now for me to help with at this distance over the internet in a help forum.
    As I mentioned at the outset , I don’t have a lot of experience with these sort of Word codings.

    As I expect you will realise, if you have read and understood the coding, that Message Box is telling you that …. something went wrong – the folder, MovedToHere , was not made as it should have been.
    That problem does not happen here on any of my computers.

    But then you say the folder was made. It’s all very confusing and not really possible for me to help here without spending many many hours of testing to try and repeat the error and problems that you are getting.


    permission denied” sounds like you are not being allowed to delete the files. There may be some file or folder protection issues of which I have no experience with.


    I don’t think I can help any more. I am out of ideas. I lack the experience with this sort of Word and Image coding. Sorry.



    Your best option would be to find someone to help you in person, or try at other forums where a lot more experienced people are. Remember to refer them to this Thread, as I mentioned previously.

    I think also, you should now understand all about the coding and how it works. So you should be able to experiment yourself and find the problem.
    If you do not understand any of the coding, I will gladly explain anything again in more detail.

    Possibly you should start again yourself: Begin by writing smaller code bits to do some of the things, like making a folder, maybe another code to copy a file etc. , etc. Convince yourself you know what is going on.

    Good luck
    If you get it all sorted, please tell us where and how. Tell us also please if you post the question in other forums. Thanks.
    Alan



    P.s. …
    Quote Originally Posted by prkhan56 View Post
    ...
    The code was copied in the Word file ....
    You still have not told me what word file??? – see my previous comments.
    Last edited by DocAElstein; 09-24-2021 at 10:05 AM.
    A Folk, A Forum, A Fuhrer ….

  9. #19
    Junior Member
    Join Date
    Aug 2021
    Posts
    13
    Rep Power
    0
    Hello Alan,
    The code is in the file you sent me back.
    Anyway, I want to thank you for all the time and help you did for me.
    I will put it on other forum as my expertise in VBA is very minimal.

    Thanks once again.

  10. #20
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Hi
    Quote Originally Posted by prkhan56 View Post
    The code is in the file you sent me back
    That explains why the macro stops when at the close - The macro is there , running, but then you close it, so its gone.
    If you run a macro that is in a document and that macro closes the document, then nothing can happen after the close because both the document and macro is no longer there.
    It is like driving a car on a journey, and on the way, in the middle of the journey, God comes and takes your car and the engine away. So the journey stops

    Like this
    WORD: [document and start macro running ]
    WORD: [document and macro running ]
    WORD: [document and macro running - macro closes the document ]
    WORD: [ _________________________ ] - all is gone. There is nothing there - no document , no running macro. Macro cannot finish - there is no macro - its gone because you closed it

    Important: You can stop a macro like this by closing the document with the macro in it. But it is dangerous to do it.
    It is like if you are in a plane and want to land. So you take the engine away. The plane will come down. If you are lucky it will come down and stop. If you are unlucky the plane may crash. You may die.
    You can stop a macro like this by closing the document with the macro in it. If you are lucky the macro will stop. If you are unlucky your computer may crash. It may die.




    Also: A .docx cannot hold a macro - you can try it - try to save a .docx file with a macro in it. - It will not work
    A macro can go in normal template or in a docm file

    Good luck
    Please let us know how you get on.
    Alan
    Last edited by DocAElstein; 09-29-2021 at 03:22 PM.
    A Folk, A Forum, A Fuhrer ….

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
  •