Using Default Path

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi folks.

I have a .xlsm spreadsheet with a number of .htm files in the same folder. The spreadsheet referrences the .htm files. I would like to know if there is a way to not having the need to define the path to open these files but to use the path that the .xlsm file was loaded from. This way I do not need to hardcode a path which will allow the spreadsheet to work no matter what falder it is placed in and the .htm's are in the same folder.

The code I'm trying to avid is below:

MyPath = "X:\Level 1\Pilot\Incident Reports\"
ChDrive MyPath
ChDir MyPath

In advance, thanks for the help...
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Can't you just get the path for the workbook the code is in like this?
Code:
MyPath = ThisWorkbook.Path
 
Upvote 0
try something like this

Code:
mypath = thisworkbook.path
chdrive left(mypath,3)
chdir mypath
 
Upvote 0
I found a solution. I am using:

MyFolder = ThisWorkbook.Path

Seems to be working fine...

Thanks,

Rocky
 
Upvote 0
Thanks folks.. seems that your reply to my post and my replay happened at the same time... I truly appreciste the quick response.
 
Upvote 0

Forum statistics

Threads
1,225,476
Messages
6,185,202
Members
453,283
Latest member
Shortm88

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