• Working with ChDir command

    Author
    Topic
    #462224

    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.)

    Viewing 2 reply threads
    Author
    Replies
    • #1175647

      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.

    • #1175686

      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!

      I’m not sure ChDir is reliable. Have you tried ChangeFileOpenDirectory?

    • #1175820

      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:

      [indent]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.[/indent]

      Some things obviously don’t change.

      • #1175857

        Thanks, all… very helpful!

        plus ça change, plus c’est la choses mauvais séjour

    Viewing 2 reply threads
    Reply To: Working with ChDir command

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: