none
Why is Current Directory used in VBA in Outlook changing? RRS feed

  • Question

  • I am trying to control the current directory for an Outlook VBA application but it is changing and I can't work out the code that is changing it. When I start Outlook the Private Sub Application_Startup() executes. It includes these lines

    shell.currentDirectory = "C:\Users\salessupport\Documents\Daron\special jobs\20180403Preprint\t\data"
    Debug.Print fso.GetAbsolutePathName(".") 

    After starting I open the immediate and I see:

    C:\Users\salessupport\Documents\Daron\special jobs\20180403Preprint\t\data

    which is what I want.

    But when I type Debug.Print fso.GetAbsolutePathName(".")  in to the immediate window I see:

    C:\Users\salessupport\Documents

    Which is incorrect. fso is a global variable.

    How can I find out why the current directory is changing?

    Friday, July 27, 2018 5:26 AM

All replies

  • Do not rely on the current path. Always specify the full path and file name.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, July 27, 2018 6:25 AM
  • I need someway to abbreviate the paths that I am using to reference files because when I am using shell commands sometimes the filenames and parameters are becoming to long. Are there any alternative methods for reducing the use of long path names that are reliable? For example if I change the current directory and execute a shell.run command in the next instructions in the same subroutine can I rely on the directory remaining stable?
    • Edited by DaronRyan Friday, July 27, 2018 6:39 AM
    Friday, July 27, 2018 6:37 AM
  • Hello DaronRyan,

    If you think the path is too long, you could save part of the path in a variable and use the other part to change folder.

    For instance

    rootPath = "C:\Users\salessupport\Documents\"
    DaronPath = rootPath & "Daron"
    dataPath = rootPath & "Daron\special jobs\20180403Preprint\t\data"

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 30, 2018 9:06 AM
  • Thank you Terry but the problem comes later. The final string has to be use in a command to another problem executing through the shell.run command. The receiving program is having trouble with the command line length. I am working on selecting a directory inside each sub (although in reality I would prefer the directory could be selected just once for the entire application). It would seem surprising if the system could not keep the directory selected at least for the execution of one subroutine, otherwise what use what the directory selection function have anyway?
    Tuesday, July 31, 2018 1:44 AM