Problem with VBIDE.CodeModule

SeniorNewbie

Board Regular
Joined
Jul 9, 2023
Messages
77
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
  2. MacOS
Hi out there!

may be someone here can help me to "remove the potatoes from my eyes" (a German saying for temporarily blindness). I need a procedure which react on the contents in a module code. Therefor it has to be read first what I'm trying with this snippet (Extensibility 5.3 must be activated):
VBA Code:
Option Explicit

Sub vbCodeTest()
Dim i As Long, iLine As Integer, sModule As String
Dim vbProj As VBIDE.VBProject, vbComp As VBIDE.VBComponent, vbCode As VBIDE.CodeModule

sModule = "Modul1"
Set vbProj = ThisWorkbook.VBProject
Set vbComp = vbProj.VBComponents(sModule)
Set vbCode = vbComp.CodeModule

MsgBox vbCode.CountOfLines

For i = 1 To vbCode.CountOfLines
    'Debug.Print vbCode.Lines(i)
    Debug.Print i
Next
End Sub
As you can see the line CountofLines - 4 is deactivated. Run the code in a testmodul and you'll see it works. But not this bloody line -4. Error message "Argument is't optional"

There's a similar code block in another module- and there it works. I compared it line by line, character by character, but I can't find the mistake.

Any ideas? THX in advance!
Senior Newbie
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
The Lines property of the CodeModule object contains two parameters -- StartLine and Count. StartLine is the number of the first line to return, and Count is the number of lines to return. So, to return each line, one line at a time, starting from line 1, try...

VBA Code:
Debug.Print vbCode.Lines(i, 1)

Hope this helps!
 
Upvote 0
Hi Domenic!
It helps! I found out by my self in the meantime, but you we're quicker to post it here.
Solutions have to be posted. Even a nut like me found it out by my self...

THX a lot!!
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,180
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top