+ Reply to Thread
Results 1 to 7 of 7

Macro works well on single file but not on all files in a single directory

  1. #1
    Registered User
    Join Date
    08-17-2013
    Location
    Pune, India
    MS-Off Ver
    Word 2007
    Posts
    4

    Macro works well on single file but not on all files in a single directory

    Iím facing quite a unique challenge in running a macro in word 2007. The macro is designed to crop unwanted parts of an image. This macro works perfectly well when I run it on a single file. However, if I invoke the macro to run on all the files within a given directory, it just doesnít seem to work. It doesnít even give me any error. It just crops the first few images, and that is all.

    I am just a novice, and would appreciate absolutely any help from the learnt members of this forum, in figuring out how to apply this code to run successfully on all the files. All help is welcome, and will be received with thanks and grace.

    -Diu

    This is what I have specifically: the code for the crop image macro I have is below.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Macro works well on single file but not on all files in a single directory

    Possibly the fact that you are saving the docx in each cycle maybe confusing the DIR statement. An alternative is to read all the file names into an array and then work through that array to crop the images.
    Martin

  3. #3
    Registered User
    Join Date
    08-17-2013
    Location
    Pune, India
    MS-Off Ver
    Word 2007
    Posts
    4

    Re: Macro works well on single file but not on all files in a single directory

    @mrice- Thank you for writing back. I am a complete newbie at this. I would greatly appreciate if you could tell me what specific modifications will I have to make to the code and what will the final code look like if I have to achieve the alternative you have suggested.
    Thank you for your time!

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Macro works well on single file but not on all files in a single directory

    Maybe something like

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit
    Posts
    816

    Re: Macro works well on single file but not on all files in a single directory


  6. #6
    Registered User
    Join Date
    08-17-2013
    Location
    Pune, India
    MS-Off Ver
    Word 2007
    Posts
    4

    Re: Macro works well on single file but not on all files in a single directory

    Thank you for taking the time to modify the code for me. I used the new code, but guess it is the CropImageMacro which is giving me a runtime error. I have attached the screen shots for your reference. I get the same runtime error when running the original FreeMeNow macro too. Any ideas what is wrong with the CropImageMacro? Is this happening because my files have different number of images, ranging from anywhere between 7-12?
    Thanks much in advance

    MacroError.pngMacroError2.png

  7. #7
    Registered User
    Join Date
    08-17-2013
    Location
    Pune, India
    MS-Off Ver
    Word 2007
    Posts
    4

    Re: Macro works well on single file but not on all files in a single directory

    Hi rollis13, apologes if I have cross posted. I thought these were 2 different forums altogether hosted on 2 different websites.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro for combining similar excel files into single file
    By jsrakesh4u in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2013, 02:06 AM
  2. [SOLVED] Need Macro to copy data from a single sheet from work books in the same directory.
    By bird970 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-21-2012, 06:10 PM
  3. merging csv files into a single xls file
    By RezDan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-03-2012, 02:16 PM
  4. Replies: 1
    Last Post: 12-21-2011, 11:00 AM
  5. Transfering files from lots of files to one single Exel master file.
    By yjacob in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 07-01-2009, 11:37 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1