Change drives and change directories

Patricia0923

New Member
Joined
Mar 18, 2014
Messages
25
Hi,
I need to write code such that when the workbook is opened at any location (can be up to 14,000 stores) I can open a directory on a virtual drive R (which is localized to that location) to access folders located there and pull data.

Currently, I inherited a file that says this, but I don't understand what it does or why it was written that way. Can anyone help, please. Thanks.

LOG_Dir = Left(ThisWorkbook.Path, Len(ThisWorkbook.Path) -5) & "\logs\"
ChDrive Left(ThisWorkbook.Path, InStr(1, ThisWorkbook.Path,":"))
ChDir ThisWorkbook.Path
ChDir "..\..\data"
DATA_DIR = CurDir()
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Without any cell data to go by, I'll take a stab in the dark.
This is probably the name of the subdirectory, plus the subdir Logs. A text string.
LOG_Dir = Left(ThisWorkbook.Path, Len(ThisWorkbook.Path) -5) & "\logs\"
This will change to the drive letter the Left generates.
ChDrive Left(ThisWorkbook.Path, InStr(1, ThisWorkbook.Path,":"))
Action to change to the subdirectory.
ChDir ThisWorkbook.Path
Another change directory.
ChDir "..\..\data"
This is a built in function that returns the current active subdirectory. E.g. When you type CMD.exe from the run box, and the DOS box opens, it typically defaults to C:\Windows\ depending on the OS. This is the CurDir If you navigate to another subdirectory, then that becomes the current subdir.
DATA_DIR = CurDir()
 
Last edited:
Upvote 0
Without any cell data to go by, I'll take a stab in the dark.
This is probably the name of the subdirectory, plus the subdir Logs. A text string.

This will change to the drive letter the Left generates.

Action to change to the subdirectory.

Another change directory.
This is a built in function that returns the current active subdirectory. E.g. When you type CMD.exe from the run box, and the DOS box opens, it typically defaults to C:\Windows\ depending on the OS. This is the CurDir If you navigate to another subdirectory, then that becomes the current subdir.


Thank you, this does help somewhat!

I appreciate it.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top