|
Самоизменяющийся код...
|
|||
---|---|---|---|
#18+
Возможно ли реализовать на VBA (Excel2k) процедуру, изменяющую другую процедуру? С помощью Код: plaintext
Можно добавить строки кода. Можно также удалить произвольные. Однако, такой метод прокатывает только для простых проектов. Когда много модулей -- после процедуры обновления Excel вызывает критическую ошибку. Может знает кто как корректно сделать обновление кода программным способом? Заранее благодарен за ответ. ... |
|||
:
Нравится:
Не нравится:
|
|||
14.07.2003, 15:14 |
|
Самоизменяющийся код...
|
|||
---|---|---|---|
#18+
Sub НайтиЗаменить(modAny As CodeModule) ' modAny модуль который будем изменять ' Example: ' Call НайтиЗаменить(Application.VBE.ActiveVBProject. _ ' VBComponents(1).CodeModule) Dim StartLine As Long Dim StartCol As Long Dim EndLine As Long Dim EndCol As Long Dim strLine As String Const Что_то = "Искомый текст" Const Изменим = Что_то & "Что то вставим" With modAny StartLine = 1 StartCol = 1 EndLine = .CountOfLines EndCol = Len(.Lines(.CountOfLines, 1)) Do While .Find(Что_то, StartLine, _ StartCol, EndLine, EndCol, True) strLine = .Lines(StartLine, 1) strLine = Left(strLine, StartCol - 1) & _ dhcReplace & Mid(strLine, EndCol) .ReplaceLine StartLine, strLine ' Reset parameters StartLine = EndLine + 1 StartCol = 1 EndLine = .CountOfLines EndCol = Len(.Lines(.CountOfLines, 1)) Loop End With End Sub Sub ListProcs(modAny As CodeModule) ' Lists all the procedures in the given code module. ' Call dhListProcs(Application.VBE.ActiveVBProject. _ ' VBComponents(1).CodeModule) Dim cLines As Long Dim lngType As Long Dim strProc As String With modAny For cLines = 1 To .CountOfLines strProc = .ProcOfLine(cLines, lngType) If strProc <> "" Then Debug.Print "Line " & cLines, _ cLines = cLines + _ .ProcCountLines(strProc, lngType) - 1 End If Next End With End Sub Sub NewModule() ' Creates a new stndard module in the active project. ' Call NewModule ' Use the active project With Application.VBE.ActiveVBProject With .VBComponents.Add(vbext_ct_StdModule) .Name = "Test" With .CodeModule .AddFromString "Global gintText As Integer" .AddFromFile "C:\TESTPROC.BAS" End With End With End With End Sub Sub dhAddCommentBlock() With Application.VBE.ActiveVBProject. _ VBComponents("Test").CodeModule ' Добавит коментарий в модуль "Test" .InsertLines 1, "'========================" .InsertLines 2, "' Created by me, " & Date .InsertLines 3, "'========================" End With End Sub Sub RemoveCommentBlock() ' Remove comment block Application.VBE.ActiveVBProject. _ VBComponents("Test").CodeModule. _ DeleteLines 1, 3 End Sub Sub EventProc() ' Creates an event procedure for a class module. Dim lngStart As Long Dim strQuotes As String strQuotes = Chr(34) With Application.VBE.ActiveVBProject. _ VBComponents.Add(vbext_ct_ClassModule).CodeModule lngStart = .CreateEventProc("Initialize", "Class") .InsertLines lngStart + 1, " ' This is a test" .InsertLines lngStart + 2, " MsgBox " & _ strQuotes & "Test" & strQuotes & ", " & _ "vbInformation" End With End Sub ... |
|||
:
Нравится:
Не нравится:
|
|||
15.07.2003, 11:19 |
|
|
start [/forum/topic.php?fid=60&gotonew=1&tid=2171035]: |
0ms |
get settings: |
11ms |
get forum list: |
14ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
45ms |
get topic data: |
12ms |
get first new msg: |
9ms |
get forum data: |
3ms |
get page messages: |
37ms |
get tp. blocked users: |
1ms |
others: | 274ms |
total: | 414ms |
0 / 0 |