Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 160
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 160
Default 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
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
reading from SQL Texas Tonie[_2_] Excel Discussion (Misc queries) 0 November 9th 07 10:59 PM
Reading XML Ajit Excel Discussion (Misc queries) 1 October 2nd 07 10:54 PM
Reading contents Fiona Excel Discussion (Misc queries) 3 June 28th 07 02:56 AM
reading xls from asp mrweb Excel Programming 0 October 20th 03 08:54 PM
sub for reading Fernando Duran Excel Programming 4 September 15th 03 07:52 PM


All times are GMT +1. The time now is 02:31 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"