VBIDE.Codemodule.addfromfile putting code in wrong place

  • Thread starter Thread starter Guga
  • Start date Start date
G

Guga

Dear all,

I am using VBIDE.Codemodule.addfromfile "NameOfFile.bas" to append a
procedure to a VBComponent. The problem is that in this VBComponent I
have variables declarations and one in the middle that is Public, and
the VBE engine is appending the procedure several lines above this
declaration, although the first procedure is several lines bellow. Any
suggestion?

Thanks,
GM
 
Sub AddProcedureToModule(CodeMod As VBIDE.CodeModule, ProcName As
String)

ProcName = ActiveWorkbook.Path & "\" & ProcName & ".bas"

CodeMod.AddFromFile ProcName

End Sub


Example of output code:
Const iEmpresasGrupo As Integer = 14
Const sIGs As String = "XPTO"
Const sForadoGrupo As String = "FORA DO GRUPO"
Dim bSilentMode As Boolean
Const cChave As Integer = 1, _
cNivel As Integer = 2, _
cTipo As Integer = 3, _
cRubricaShow As Integer = 5, _
cRubricaEdit As Integer = 6, _
cIG As Integer = 7, _
cDir As Integer = 8, _
cFirstValue = 10, _
cLastValue = 56, _
SUB PROCNAME
NEW CODE
END SUB
cFilter = 95, _
cFiltroIntroducao = 87, _
cChaveComposta = 104

'Other variables:
Public rCelulaActiva As Range
Dim rCelula As Range
Dim iAnswer As Integer
Dim iContador As Integer

As you can see the new procedure is being inserted in the middle of
the declarations... The .CountOfDeclarationLines property returns the
correct number of lines, which would result in the insertion of the
new procedure to be in the right place.

I am working in a work around with .insertlines method.

Thanks for your reply.
Regards,
GM
 
Back
Top