Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default programmaticly change code

I want to have a hard coded value for a variable and then
be able to use code to alter the hardcoded value.
I have seen advice regarding how to get basic info like
the number of lines of code in a routine etc but nothing
that shows how to find & replace a line of code with new
code.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default programmaticly change code

Bruce,

Try something like the following. It will change the first occurrence in
Module2 of

X = 123
to
X =234


Dim SL As Long
Dim EL As Long
Dim SC As Long
Dim EC As Long
Dim Found As Boolean

With ThisWorkbook.VBProject.VBComponents("Module2").Cod eModule
SL = 1
EL = .CountOfLines
SC = 1
EC = 1024
Found = .Find("X = 123", SL, SC, EL, EC, True, False, False)
If Found = True Then
.DeleteLines SL
.InsertLines SL, "X = 234"
End If
End With


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com


"bruce" wrote in message
...
I want to have a hard coded value for a variable and then
be able to use code to alter the hardcoded value.
I have seen advice regarding how to get basic info like
the number of lines of code in a routine etc but nothing
that shows how to find & replace a line of code with new
code.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I change this code? OrlaLynch Excel Discussion (Misc queries) 1 June 11th 08 03:06 PM
VBA Code to Change the Tab Name Michael in Texas Excel Discussion (Misc queries) 1 March 28th 07 03:07 AM
VBA Code to Change the Tab Name Gary''s Student Excel Discussion (Misc queries) 0 March 28th 07 12:05 AM
combo box on change code frendabrenda1 Excel Discussion (Misc queries) 0 April 10th 06 04:21 PM
Change to Code Chip Pearson Excel Programming 4 July 28th 03 10:54 PM


All times are GMT +1. The time now is 01:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"