如果我在Excel VBE中打开了一些VB组件,并且如图所示突出显示了一些文本,
有没有办法通过编程获取文本“zBool”?
最好不要使用Sendkeys
6x新西兰Steinlager啤酒(一个很好的解决方案),为另一个好的解决方案
问:为什么黑羊比白羊少吃?
答:因为没有那么多
If I have some VB Component open in the Excel VBE, with some text highlighted as shown,
Is there a way to programmatically grab the text "zBool"?
Preferrably NOT using Sendkeys
6x New Zealand Steinlager Beers (a good solution), for another good solution
Q: Why do black sheep eat less than white sheep?
A: Because there aren't as many of them
最满意答案
添加对“Microsoft Visual Basic for Applications扩展性...”的引用
Sub Tester() Dim oVBE As vbe Dim startLine As Long, startCol As Long Dim endLine As Long, endCol As Long Dim sContent As String, tmp As String, l As Long Set oVBE = Application.vbe oVBE.ActiveCodePane.GetSelection _ startLine, startCol, endLine, endCol For l = startLine To endLine tmp = oVBE.ActiveCodePane.CodeModule.Lines(l, 1) If l = endLine Then tmp = Left(tmp, endCol - 1) If l = startLine Then tmp = Right(tmp, (Len(tmp) - startCol) + 1) sContent = sContent & IIf(Len(sContent) > 0, Chr(10), "") & _ tmp Next l Debug.Print sContent End SubGetSelection方法: http : //msdn.microsoft.com/en-us/library/aa443954( v=vs.60) .aspx
请参阅此处了解如何使用返回的信息访问实际文本: http : //www.cpearson.com/excel/vbe.aspx (我确定它在某处...)
编辑 - 为了我自己的教育,为你做了这个... 我会把它放在你的标签上;-)
Add a reference to "Microsoft visual basic for applications extensibility..."
Sub Tester() Dim oVBE As vbe Dim startLine As Long, startCol As Long Dim endLine As Long, endCol As Long Dim sContent As String, tmp As String, l As Long Set oVBE = Application.vbe oVBE.ActiveCodePane.GetSelection _ startLine, startCol, endLine, endCol For l = startLine To endLine tmp = oVBE.ActiveCodePane.CodeModule.Lines(l, 1) If l = endLine Then tmp = Left(tmp, endCol - 1) If l = startLine Then tmp = Right(tmp, (Len(tmp) - startCol) + 1) sContent = sContent & IIf(Len(sContent) > 0, Chr(10), "") & _ tmp Next l Debug.Print sContent End SubGetSelection method: http://msdn.microsoft.com/en-us/library/aa443954(v=vs.60).aspx
See here for how to use that returned information to access the actual text: http://www.cpearson.com/excel/vbe.aspx (I'm sure it's there somewhere...)
EDIT - did that for you for my own education... I'll put it on your tab ;-)
更多推荐
发布评论