Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reading codelines?
Hi guys,
Does any of you have a way of reading the first 10 lines of a code module? To be specific, I need to read the first 10 lines of the code in the module called 'Module1' into a string-variable. Currently, I'm doing this by first exporting the module, and then reading it back in, as a plain text-file. But, I'm hoping to avoid the external exporting and reading, if possible? Anyone has a way of reading those code lines directly into a variable? Thanks, CE |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reading codelines?
Charlotte E. wrote:
Hi guys, Does any of you have a way of reading the first 10 lines of a code module? To be specific, I need to read the first 10 lines of the code in the module called 'Module1' into a string-variable. Currently, I'm doing this by first exporting the module, and then reading it back in, as a plain text-file. But, I'm hoping to avoid the external exporting and reading, if possible? Anyone has a way of reading those code lines directly into a variable? Thanks, CE step 1 Tools - References and add Microsoft Visual Basic for Application Extensibility library step 2 Enable trust to visual basic project somewhere in excel options. step 3 paste this code Sub TenLines() Dim vb As VBE Dim vpb As VBProject Set vbp = ThisWorkbook.VBProject Dim c As VBComponent For Each c In vbp.VBComponents If c.Name = "Module1" Then Dim cm As CodeModule Set cm = c.CodeModule Dim code_text As String code_text = cm.Lines(1, WorksheetFunction.Min(10, cm.CountOfLines)) Debug.Print code_text End If Next c End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reading codelines?
witek wrote:
Charlotte E. wrote: Hi guys, Does any of you have a way of reading the first 10 lines of a code module? To be specific, I need to read the first 10 lines of the code in the module called 'Module1' into a string-variable. Currently, I'm doing this by first exporting the module, and then reading it back in, as a plain text-file. But, I'm hoping to avoid the external exporting and reading, if possible? Anyone has a way of reading those code lines directly into a variable? Thanks, CE step 1 Tools - References and add Microsoft Visual Basic for Application Extensibility library step 2 Enable trust to visual basic project somewhere in excel options. step 3 paste this code Sub TenLines() Dim vb As VBE Dim vpb As VBProject Set vbp = ThisWorkbook.VBProject Dim c As VBComponent For Each c In vbp.VBComponents If c.Name = "Module1" Then Dim cm As CodeModule Set cm = c.CodeModule Dim code_text As String code_text = cm.Lines(1, WorksheetFunction.Min(10, cm.CountOfLines)) Debug.Print code_text End If Next c End Sub Dim vb As VBE is not needed. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reading codelines?
Thanks, Witek,
I'm a little hung up the next few days, but I'll test it as soon as possible... CE "witek" wrote in message ... Charlotte E. wrote: Hi guys, Does any of you have a way of reading the first 10 lines of a code module? To be specific, I need to read the first 10 lines of the code in the module called 'Module1' into a string-variable. Currently, I'm doing this by first exporting the module, and then reading it back in, as a plain text-file. But, I'm hoping to avoid the external exporting and reading, if possible? Anyone has a way of reading those code lines directly into a variable? Thanks, CE step 1 Tools - References and add Microsoft Visual Basic for Application Extensibility library step 2 Enable trust to visual basic project somewhere in excel options. step 3 paste this code Sub TenLines() Dim vb As VBE Dim vpb As VBProject Set vbp = ThisWorkbook.VBProject Dim c As VBComponent For Each c In vbp.VBComponents If c.Name = "Module1" Then Dim cm As CodeModule Set cm = c.CodeModule Dim code_text As String code_text = cm.Lines(1, WorksheetFunction.Min(10, cm.CountOfLines)) Debug.Print code_text End If Next c End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
reading from SQL | Excel Discussion (Misc queries) | |||
Reading XML | Excel Discussion (Misc queries) | |||
Reading contents | Excel Discussion (Misc queries) | |||
reading xls from asp | Excel Programming | |||
sub for reading | Excel Programming |