Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, hopefully someone can help me before my frustration mounts.

    I have a simple task: open each file in a folder and use SaveAs to convert from DOCX to DOC. (Stop me here if you know of a better way!) Basically, I used the "ChDir" command to begin the routine, followed by the typical 'do-while-dir <> ""' approach. The problem is, after I use the SaveAs command, the default folder changes to whatever my "File Locations" default is and the subsequent Dir fails to return the next pertinent file!

    This is the first time I'm manipulating files like this in 2007. Is this "normal" behavior? Shouldn't the ChDir command stick? More to the point, why does the SaveAs command change the current directory?? (It's not a drive issue, since both the ChDir and the default file location are on my C:-drive.)

    (BTW, I should note that I can certainly work around this phenomenon (by including the full path in the DIR command, etc.) but I'd nonetheless like to know if anyone knows of the rationale for the SaveAs command changing the current directory whenever it's called.)
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I can't explain the behavior that you describe (I don't have Office 2007), but in general I find it safer to use the full path of files than to rely on ChDir.

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='Mesaka' post='791534' date='31-Aug-2009 10:14']I have a simple task: open each file in a folder and use SaveAs to convert from DOCX to DOC. (Stop me here if you know of a better way!) Basically, I used the "ChDir" command to begin the routine, followed by the typical 'do-while-dir <> ""' approach. The problem is, after I use the SaveAs command, the default folder changes to whatever my "File Locations" default is and the subsequent Dir fails to return the next pertinent file![/quote]
    I'm not sure ChDir is reliable. Have you tried ChangeFileOpenDirectory?

  4. #4
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post
    As Jefferson states, you need to use ChangeFileOpenDirectory. Below is a quote from a book I have - "Word 97 Macro & VBA Handbook" by Guy Hart-Davis:

    When working with the Open dialog box in macros, there's one complicating factor for changing drives and folders; for reasons best known to Microsoft, VBA uses a special method for setting the folder to display in the Open dialog box. ... You can use ChDrive and ChDir to change the current drive and folder until you're blue in the face, but the Open dialog box won't pay a blind bit of notice-you need to use ChangeFileOpenDirectory instead.

    Some things obviously don't change.

  5. #5
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, all... very helpful!

    plus ça change, plus c'est la choses mauvais séjour
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

Posting Permissions

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