Can VBA Code change itself?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a spreadsheet I want to distribute to various people. When it runs,
it pulls data from an outside spreadsheet into itself and processes it. Each
person that I distribute it to will have the data to be pulled in a folder on
their machine. And the spreadsheet I give them will probably be in the same
folder.

Can I set a variable in the code with an initial null value, then put a
textbox on the menu form, have them enter the folder name, then permanently
change the variable value to what they enter, so that the next time they open
the spreadsheet, the folder name they entered last time is already there.
 
I would create a new text file in the users network document and settings
Directory. Give it your own extension and create startup excel information.
When the macro is run have it open the text file and get needed info.
 
Have a look at GetSetting and SaveSetting in VBA. If you are positive
that the folder containing the files will also be the same folder
where the workbook containing the sode will be stored, you could just
grab the directory of the code workbook and use that.
 
Bill,

In your spreadsheet, use code like this

Dim myPath As String

myPath = ThisWorkbook.Path
ChDir myPath

It will change your default folder for searches, etc. to the folder that the ss file is stored in.

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top