Set the save path based on a cell value

Yeoman.jeremy

Board Regular
Joined
Apr 4, 2011
Messages
90
Hi there,

Is there a way to set the save path as a cell value?

At the moment i set the path using
Code:
ChDir "C:\Users\owner\Desktop\Development"
in the vb coding, but it gets tedious, as i have to change this for 4 different modules in at least 3 computers in each store, in approximately 18 stores everytime i make an update to my workbook.

I want the directory to be written into a cell, which this coding points to so i don't have to search throuhg my modules to find the specific piece of code, instead i can just change the directory each computer


help[ much apppreciated,
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
[QUOTE
Code:
ChDir "C:\Users\owner\Desktop\Development"
,[/QUOTE]

If I understand what you want to do then yes you can.
You could set a public string variable like strFilePath.
then you would set strFilePath = to whatever cell you want.

then your code would look like something like
ChDir strFilePath

Also instead of a cell you could just put this line of code in the initialize event if you know the path.

public strFilePath as string (I think this has to go in a module though)
strFilePath ="whatever the path is"

and then replace all of the previous code with ChDir strFilePath
That way you should only have to change it in one place.
Hope that helps
 
Upvote 0
Hi there,

Is there a way to set the save path as a cell value?

At the moment i set the path using
Code:
ChDir "C:\Users\owner\Desktop\Development"
in the vb coding, but it gets tedious, as i have to change this for 4 different modules in at least 3 computers in each store, in approximately 18 stores everytime i make an update to my workbook.

I want the directory to be written into a cell, which this coding points to so i don't have to search throuhg my modules to find the specific piece of code, instead i can just change the directory each computer


help[ much apppreciated,

Something like:
Code:
ChDir "C:\Users\owner\Desktop\" & Worksheets("Sheet1").Range("A1").Value
 
Upvote 0
Something like:
Code:
ChDir "C:\Users\owner\Desktop\" & Worksheets("Sheet1").Range("A1").Value

The point is that the names of computers, and their user log ins is all different, so i would still have to go in and change the "C:\Users....." etc

I did try using
Code:
ChDir Sheets("Job Sheet").Range("E9")

but it came up with the error "path not found"

I'll try adding .value on the end though, and see if it recognises it then

Edit: still says "path not found
 
Last edited:
Upvote 0
The point is that the names of computers, and their user log ins is all different, so i would still have to go in and change the "C:\Users....." etc

In this case you can use
activeworkbook.path


ChDir activeworkbook.path & Worksheets("Sheet1").Range("A1").text
you might need a "/" before worksheets
 
Last edited:
Upvote 0
I'll try adding .value on the end though, and see if it recognises it then

Edit: still says "path not found

Yes, you need the .Value (or .Text) argument. And ensure that 'Job Sheets'!E9 contains


C:\Users\owner\Desktop\Development
And nothing else. No " or ' before or after it.
 
Last edited:
Upvote 0
In this case you can use
activeworkbook.path


ChDir activeworkbook.path & Worksheets("Sheet1").Range("A1").text
you might need a "/" before worksheets

Awesome!
It's now saving it without an error prompt (without the "/" - with it. it gave an error)

although there is still one slight problem.
the cell value is

C:\Users\owner\Desktop\Development\Tested Results\
Yet it saves the file in the 'development' folder.
Any ideas?
 
Upvote 0
Awesome!
It's now saving it without an error prompt (without the "/" - with it. it gave an error)

although there is still one slight problem.
the cell value is

C:\Users\owner\Desktop\Development\Tested Results\
Yet it saves the file in the 'development' folder.
Any ideas?
What's the piece of code that saves the workbook? The bug may be there
 
Upvote 0
the cell value is C:\Users\owner\Desktop\Development\Tested Results\ Any ideas?[/QUOTE said:
Not Sure but I'll give you some testing code
Are you writing in the cell value or getting it from somewhere else?

try this for testing

dim strTempPath as string
dim strTempPath2 as string
dim strSavePath as string
strTempPath = Worksheets("Sheet1").Range("A1").text
strTempPath2 = activeworkbook.path
strSavePath = strTempPath & strTempPath2
ChDir strSavePath

let me know what strSavePath equals
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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