• ChDir not working as expected (Word 2000)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » ChDir not working as expected (Word 2000)

    Author
    Topic
    #378237

    I am creating an index using RD fields (the Index field is in one document with RD fields that reference the documents that should be included in the index). The RD fields do not specify a path because all of the files are in the same directory. For example, {RD “file to be indexed.doc”}

    If I open my index.doc file using File-Open (navigating to the correct directory), then everything works fine. If I happen to open index.doc from Explorer, where I don’t navigate using File-Open, then updating the index gives an error, something like “Word cannot find the file C:My Documents|File to be indexed.doc,” if Word’s default Documents location is C:My Documents.

    I tried writing a macro with the first line being:

    ChDir ActiveDocument.Path

    To me, that should tell Word to change its current path to the location of the open document. If I follow that line up with:

    If CurDir ActiveDocument.Path then Stop

    And Word thinks everything is fine. It *thinks* its current path is the right one. If I update my index, though, I still get the error. If I click File-Open after getting the error, C:My Documents is the directory displayed.

    Is there something I’m missing, or is this a bug in the index process? Have I misunderstood the ChDir function?

    Thanks,
    Bob

    Viewing 0 reply threads
    Author
    Replies
    • #625360

      You need to set Options.DefaultFilePath(wdDocumentsPath) to point to the correct location, using a syntax like…

      Options.DefaultFilePath(wdDocumentsPath) = "C:StuartTemp"
      

      StuartR

      Edited by StuartR to correct a mistake

      • #625362

        Thanks for the quick reply. I would think, though, that this would set the default path, so that every time I start Word, it would default to this directory. I only want the path to be set for the current instance of Word (the “current” path, not the “default” path). This application runs on many different machines and on documents in many different directories. I don’t want to continually reset Word’s default document directory, and I don’t want to change Word’s defaults on my client’s machines.

        • #625365

          If it is only for this one occassion then try

          ChangeFileOpenDirectory("c:StuartTemp")
          

          StuartR

          • #625367

            THAT’S what I was looking for!

            Pity that setting isn’t linked from ChDir or DefaultFilePath in the Help. I might have found it myself smile

            Thanks Stuart!

    Viewing 0 reply threads
    Reply To: ChDir not working as expected (Word 2000)

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

    Your information: