LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Replacing code at runtime

Ajit,

Presuming you know the module name, you can use cod elike the macro below,
which will require a reference to MS VBA Extensibility. This also assumes
that the line you're looking for is unique.

HTH,
Bernie
MS Excel MVP

Sub AddLineAfterExistingCode()
Dim myCode As String
Dim OldCode As String
Dim NewCode As String

OldCode = "MsgBox ""Hello"""
NewCode = "MsgBox ""Hello There"""

With ActiveWorkbook.VBProject.VBComponents.Item("Module Name").CodeModule

myCode = .Lines(1, .CountOfLines)
myCode = Replace(myCode, OldCode, OldCode & Chr(10) & NewCode)

..DeleteLines 1, .CountOfLines
..InsertLines .CountOfLines + 1, myCode

End With

End Sub


"Ajit" wrote in message
...
This forum had been of great help at all the times..

I have posted this issue before too..but may be I could not explain
properly...trying to give another shot.

I have couple of templates and i need to add a line of code to all of them
(to the same procedure in a same module)...i am able to find the procedure
and add a line of code at the end. But what if i had to do find some code

and
add it in next line....I am not able to find the linenumber of the code

that
i do find for.

Suggestions will be greatly appreciated.

Thanks,


--
Ajit



 
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
runtime error code 1004 Karen Excel Worksheet Functions 1 May 13th 10 12:21 AM
question about excessive code in replacing #N/A when using VLOOKUP njuneardave Excel Discussion (Misc queries) 4 June 21st 06 03:14 AM
Repost with code - Runtime error '1004' muziq2[_20_] Excel Programming 5 July 17th 04 12:46 AM
runtime Control and code in VBA Anu Excel Programming 1 January 12th 04 04:44 AM
RunTime code problem drum118 Excel Programming 4 July 19th 03 12:15 PM


All times are GMT +1. The time now is 07:31 PM.

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

About Us

"It's about Microsoft Excel"