ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   modifying code in run time (https://www.excelbanter.com/excel-programming/317139-modifying-code-run-time.html)

alfaista

modifying code in run time
 
i am sure there is an easier way to do this, and if so i'd sure like to know
what it is!!

in the meantime, i have an excel file that references a couple of add-ins.
it has code that executes on the workbook events and on the worksheet events.
(the code just calls code from the add-in).
what i would like to be able to do is have to user save it as a
"non-application-file" meaning that it won't have the links or code, so they
can hand their files off to someone who does not have the application on
their system and they may still view it without a bunch of errors.
right now, if the user chooses to save the file that way, code excecutes
that simply comments out the calls within the workbook.
the trick is, when opening the workbook, i would like to check to see if the
code is commented out, and if so place a "re-set" button on the menu so it
can be re-set to its original form.
the code i have to do this is as follows:

Private Sub Workbook_Open()

Dim lCount As Long
Dim bReSet As Boolean
Dim vFolderPath As Variant

vFolderPath = QueryValue("Software\MyApp\DataLocation", "AddInPath")

If IsEmpty(vFolderPath) Then
Exit Sub
End If

lCount =
ActiveWorkbook.VBProject.VBE.SelectedVBComponent.C odeModule.CountOfLines

bReSet =
ActiveWorkbook.VBProject.VBE.SelectedVBComponent.C odeModule.Find("' MyApp",
1, 1, lCount, 1)

If bReSet Then ReSetButton

MyAppWorkbook_Open

End Sub

problem #1, the code can not be protected or this does not work. big
drawback.
problem #2, this doesn't always work! if i run it from design mode, it
works fine. i close and open the file, no errors, but the reset button is
not loaded.

any suggestions would be greatly appreciated!!!!



okeefe58

modifying code in run time
 
alfaista-did you get any notice of replies in your email that you shouldnt
have?--I have a notice of reply for this post as if I posted it? that kind of
worries me--(security?) maybe you and I have similar email addresses-weird
huh?

"alfaista" wrote:

i am sure there is an easier way to do this, and if so i'd sure like to know
what it is!!

in the meantime, i have an excel file that references a couple of add-ins.
it has code that executes on the workbook events and on the worksheet events.
(the code just calls code from the add-in).
what i would like to be able to do is have to user save it as a
"non-application-file" meaning that it won't have the links or code, so they
can hand their files off to someone who does not have the application on
their system and they may still view it without a bunch of errors.
right now, if the user chooses to save the file that way, code excecutes
that simply comments out the calls within the workbook.
the trick is, when opening the workbook, i would like to check to see if the
code is commented out, and if so place a "re-set" button on the menu so it
can be re-set to its original form.
the code i have to do this is as follows:

Private Sub Workbook_Open()

Dim lCount As Long
Dim bReSet As Boolean
Dim vFolderPath As Variant

vFolderPath = QueryValue("Software\MyApp\DataLocation", "AddInPath")

If IsEmpty(vFolderPath) Then
Exit Sub
End If

lCount =
ActiveWorkbook.VBProject.VBE.SelectedVBComponent.C odeModule.CountOfLines

bReSet =
ActiveWorkbook.VBProject.VBE.SelectedVBComponent.C odeModule.Find("' MyApp",
1, 1, lCount, 1)

If bReSet Then ReSetButton

MyAppWorkbook_Open

End Sub

problem #1, the code can not be protected or this does not work. big
drawback.
problem #2, this doesn't always work! if i run it from design mode, it
works fine. i close and open the file, no errors, but the reset button is
not loaded.

any suggestions would be greatly appreciated!!!!



alfaista

modifying code in run time
 
no, no notification at all

"okeefe58" wrote:

alfaista-did you get any notice of replies in your email that you shouldnt
have?--I have a notice of reply for this post as if I posted it? that kind of
worries me--(security?) maybe you and I have similar email addresses-weird
huh?

"alfaista" wrote:

i am sure there is an easier way to do this, and if so i'd sure like to know
what it is!!

in the meantime, i have an excel file that references a couple of add-ins.
it has code that executes on the workbook events and on the worksheet events.
(the code just calls code from the add-in).
what i would like to be able to do is have to user save it as a
"non-application-file" meaning that it won't have the links or code, so they
can hand their files off to someone who does not have the application on
their system and they may still view it without a bunch of errors.
right now, if the user chooses to save the file that way, code excecutes
that simply comments out the calls within the workbook.
the trick is, when opening the workbook, i would like to check to see if the
code is commented out, and if so place a "re-set" button on the menu so it
can be re-set to its original form.
the code i have to do this is as follows:

Private Sub Workbook_Open()

Dim lCount As Long
Dim bReSet As Boolean
Dim vFolderPath As Variant

vFolderPath = QueryValue("Software\MyApp\DataLocation", "AddInPath")

If IsEmpty(vFolderPath) Then
Exit Sub
End If

lCount =
ActiveWorkbook.VBProject.VBE.SelectedVBComponent.C odeModule.CountOfLines

bReSet =
ActiveWorkbook.VBProject.VBE.SelectedVBComponent.C odeModule.Find("' MyApp",
1, 1, lCount, 1)

If bReSet Then ReSetButton

MyAppWorkbook_Open

End Sub

problem #1, the code can not be protected or this does not work. big
drawback.
problem #2, this doesn't always work! if i run it from design mode, it
works fine. i close and open the file, no errors, but the reset button is
not loaded.

any suggestions would be greatly appreciated!!!!




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

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