Cursor Position in VBE

  • Thread starter Thread starter ehntd
  • Start date Start date
E

ehntd

Hi, I got the following code for inserting lines into my program:

Sub ImportModuleCode(ByVal wb As Workbook, _
ByVal ModuleName As String, ByVal ImportFromFile As String)
' imports code to ModuleName in wb from a textfile name
ImportFromFile
Dim VBCM As CodeModule
If Dir(ImportFromFile) = "" Then Exit Sub
On Error Resume Next
Set VBCM = wb.VBProject.VBComponents(ModuleName).CodeModule
If Not VBCM Is Nothing Then
VBCM.AddFromFile ImportFromFile
Set VBCM = Nothing
End If
On Error GoTo 0
End Sub

The problem is that it inserts the code from the file in the positio
that the cursor was set at.

How can I a) change the cursor position or b) make it insert the tex
from the file in the lines that I want
 
Hi Ehntd,
The problem is that it inserts the code from the file in the position
that the cursor was set at.

How can I a) change the cursor position

Dim oCP As CodePane

'Move the cursor to line 10
Set oCP = VBCM.CodePane
oCP.SetSelection 10,0,10,0
or b) make it insert the text
from the file in the lines that I want?

Parse the file yourself (using VBA's File I/O) and use VBCM.InsertLines
to insert each line into the module.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top