ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBIDE.Codemodule.addfromfile putting code in wrong place (https://www.excelbanter.com/excel-programming/445056-vbide-codemodule-addfromfile-putting-code-wrong-place.html)

Guga

VBIDE.Codemodule.addfromfile putting code in wrong place
 
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

Tim Williams[_4_]

VBIDE.Codemodule.addfromfile putting code in wrong place
 
Show your code.



On Oct 16, 6:07*pm, Guga wrote:
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



Guga

VBIDE.Codemodule.addfromfile putting code in wrong place
 
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

Tim Williams[_4_]

VBIDE.Codemodule.addfromfile putting code in wrong place
 
Was your .bas file exported from Excel? The sample on the MS site
uses a plain Text file, so maybe that's the problem.

http://support.microsoft.com/kb/245801

Tim


On Oct 17, 5:15*am, Guga wrote:
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




All times are GMT +1. The time now is 08:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com