ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can VBA Code change itself? (https://www.excelbanter.com/excel-programming/397406-can-vba-code-change-itself.html)

BillCPA

Can VBA Code change itself?
 
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.

--
Bill @ UAMS

joel

Can VBA Code change itself?
 
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.

"BillCPA" wrote:

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.

--
Bill @ UAMS


JW[_2_]

Can VBA Code change itself?
 
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.
BillCPA wrote:
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.

--
Bill @ UAMS



Bernie Deitrick

Can VBA Code change itself?
 
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


"BillCPA" <Bill @ UAMS wrote in message ...
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.

--
Bill @ UAMS





All times are GMT +1. The time now is 05:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com