ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do you get the selection in the VBE Active window (https://www.excelbanter.com/excel-programming/428861-how-do-you-get-selection-vbe-active-window.html)

Mike[_113_]

How do you get the selection in the VBE Active window
 
I am trying to get the Selected Text from the Active VBE window.

Application.VBE.ActiveCodePane.GetSelection

gets me the start and end lines and the start and end columns in the Module.
However, it seems that I need the Module Name that it is referring to, and I
can't find any way to do this.

Any ideas??



OssieMac

How do you get the selection in the VBE Active window
 
Hi Mike,

Interesting exercise.

XL2007 Visual basic Help searched under "Item Method (VBA Add-In Object
Model)" says CodePanes No unique string associated with this collection.

So it appears that you cannot replace the index number with a string.

I tested like this:-

Sub TestGetSelection()

Dim startline As Long
Dim startcol As Long
Dim endline As Long
Dim endcol As Long
Dim i As Long

For i = 1 To Application.VBE.CodePanes.Count
If Application.VBE.CodePanes(i).CodeModule = "Module2" Then
Exit For
End If
Next i

Application.VBE.CodePanes(i).GetSelection _
startline, startcol, endline, endcol

MsgBox Application.VBE.CodePanes(i) _
.CodeModule & vbCrLf & _
"startline = " & startline & vbCrLf & _
"startcol = " & startcol & vbCrLf & _
"endline = " & endline & vbCrLf & _
"endcol = " & endcol

End Sub

--
Regards,

OssieMac




All times are GMT +1. The time now is 07:18 AM.

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