ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   make macro change (delete) its own code (https://www.excelbanter.com/excel-programming/308057-make-macro-change-delete-its-own-code.html)

as_sass

make macro change (delete) its own code
 
Hi,

quick question:

Can I make a macro manipulate it's own code?

In particular, I am trying to write a macro that deletes a particula
line (let's say the 5th) from its own code after it has been executed.

Actually, it would be even better if it just deleted some character
from tha row (e.g., character 15 to 20). Or substitute the row with st
else. Or sybstitute a certain word in the row with another. You get th
picture...

Any help appreciated, as always!

a

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

make macro change (delete) its own code
 
Why not just use an If test, setting a global variable at the appropriate
point. Lot more maintainable than self-deleting code.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"as_sass " wrote in message
...
Hi,

quick question:

Can I make a macro manipulate it's own code?

In particular, I am trying to write a macro that deletes a particular
line (let's say the 5th) from its own code after it has been executed.

Actually, it would be even better if it just deleted some characters
from tha row (e.g., character 15 to 20). Or substitute the row with sth
else. Or sybstitute a certain word in the row with another. You get the
picture...

Any help appreciated, as always!

as


---
Message posted from http://www.ExcelForum.com/




as_sass[_2_]

make macro change (delete) its own code
 
Bob,

sounds good, if I only knew how that worked... Basically what I need i
some variable in my macro that is set to a specific value, but tha
value changes to something new once the macro is executed.

As I'm new with this, I'll rephrase it to improve the chance that s
understands me:

Let's say I'm setting
check = 12345
And then have an InputBox where the user inputs a 5 digit code.
Then the input is compared with "check" (If..Then).
Afterwards, "check" should be set to a new, predetermined value.

It may well be that what you wrote is exactly it, only I really don'
know what you mean...

Thank you so much for your help!

a

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

make macro change (delete) its own code
 
This is the sort of thing I mean

Public RunBefore as Boolean

Sub as_sass_Proc()
Dim check

If Not RunBefore Then
check = 12345
RunBefore = False
Else
check = 98765
EndIf

ans = InputBox("Supply Value")

If ans = check Then
'etc.


End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"as_sass " wrote in message
...
Bob,

sounds good, if I only knew how that worked... Basically what I need is
some variable in my macro that is set to a specific value, but that
value changes to something new once the macro is executed.

As I'm new with this, I'll rephrase it to improve the chance that sb
understands me:

Let's say I'm setting
check = 12345
And then have an InputBox where the user inputs a 5 digit code.
Then the input is compared with "check" (If..Then).
Afterwards, "check" should be set to a new, predetermined value.

It may well be that what you wrote is exactly it, only I really don't
know what you mean...

Thank you so much for your help!

as


---
Message posted from http://www.ExcelForum.com/




Bob Phillips[_6_]

make macro change (delete) its own code
 
Sorry, slight typo, should be

Public RunBefore as Boolean

Sub as_sass_Proc()
Dim check

If Not RunBefore Then
check = 12345
RunBefore = True
Else
check = 98765
EndIf

ans = InputBox("Supply Value")

If ans = check Then
'etc.


End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bob Phillips" wrote in message
...
This is the sort of thing I mean

Public RunBefore as Boolean

Sub as_sass_Proc()
Dim check

If Not RunBefore Then
check = 12345
RunBefore = False
Else
check = 98765
EndIf

ans = InputBox("Supply Value")

If ans = check Then
'etc.


End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"as_sass " wrote in message
...
Bob,

sounds good, if I only knew how that worked... Basically what I need is
some variable in my macro that is set to a specific value, but that
value changes to something new once the macro is executed.

As I'm new with this, I'll rephrase it to improve the chance that sb
understands me:

Let's say I'm setting
check = 12345
And then have an InputBox where the user inputs a 5 digit code.
Then the input is compared with "check" (If..Then).
Afterwards, "check" should be set to a new, predetermined value.

It may well be that what you wrote is exactly it, only I really don't
know what you mean...

Thank you so much for your help!

as


---
Message posted from http://www.ExcelForum.com/







All times are GMT +1. The time now is 12:35 PM.

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