![]() |
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. |
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. |
All times are GMT +1. The time now is 11:39 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com