如何获取VBE中的, 鼠标选中文本?

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: 如何获取VBE中的, 鼠标选中文本?

Re: 如何获取VBE中的, 鼠标选中文本?

Post by aamii » 06 Aug 2018, 22:02

aamii wrote:第一个问题:
^c
第二个问题:
F9::
ControlFocus ,VbaWindow3,ahk_class wndclass_desked_gsk
ControlSend ,VbaWindow3,{CtrlDown}a{CtrlUp}{Delete},ahk_class wndclass_desked_gsk
return
第二个问题是可行的,实际上,你还可以借助vba自身的sendkeys

Code: Select all

#IfWinActive Microsoft Visual Basic for Applications
F9::excel_get().Application.SendKeys( "^g ^a {BackSpace}")
#IfWinActive

Re: 如何获取VBE中的, 鼠标选中文本?

Post by aamii » 06 Aug 2018, 18:50

建议你插入代码的时候
使用

Code: Select all

Example

Re: 如何获取VBE中的, 鼠标选中文本?

Post by cgx5871 » 06 Aug 2018, 09:11

Sub ClearImmediate()
Debug.Print VBA.String(200, vbNewLine)
'For a = 1 To 200
'Debug.Print ""
'Next
End Sub

oExcel.Run(oExcel.ActiveWorkbook.Name . "!ClearImmediate")

Re: 如何获取VBE中的, 鼠标选中文本?

Post by cgx5871 » 06 Aug 2018, 09:10

aamii wrote:第一个问题:
^c
第二个问题:
F9::
ControlFocus ,VbaWindow3,ahk_class wndclass_desked_gsk
ControlSend ,VbaWindow3,{CtrlDown}a{CtrlUp}{Delete},ahk_class wndclass_desked_gsk
return
这两个的方法都太土了.
还容易误操作.
找到一个曲线救国的.
VBcode=
(
Sub myFunction()
Worksheets(1).Range("C1").Value = 99
End Sub
)

Excel_Run("myFunction", VBcode) ; Changed: pass VBA code text to the function
return

Excel_Run(sFunction, VBcode){
;~ FilePath := C:\Users\KostasK\Desktop\Plano.xlsx
FilePath := A_ScriptDir "\Plano.xlsx" ; Changed for testing
oExcel := ComObjCreate("Excel.Application")
oExcel.Visible := true ; Changed for testing
oWorkbook := oExcel.Workbooks.Open(FilePath)

; We already have a reference to the Excel Application and Workbook objects. Don't need Excel_Get
Excel_ImportCode(VBcode, oWorkbook) ; Changed: Pass the workbook to use to Excel_ImportCode
oExcel.Run(sFunction) ; Changed

;~ oWorkbook.Save ; Changed for testing
;~ oExcel.Quit ; Changed for testing
}

Excel_ImportCode(VBcode, WorkbookObj){
if fileexist(A_ScriptDir . "\tempvbcode.txt")
FileDelete, %A_ScriptDir%\tempvbcode.txt
FileAppend, %VBcode%, %A_ScriptDir%\tempvbcode.txt
WorkbookObj.VBProject.VBComponents.Import(A_ScriptDir . "\tempvbcode.txt")
}

Re: 如何获取VBE中的, 鼠标选中文本?

Post by aamii » 06 Aug 2018, 00:04

第一个问题:
^c
第二个问题:
F9::
ControlFocus ,VbaWindow3,ahk_class wndclass_desked_gsk
ControlSend ,VbaWindow3,{CtrlDown}a{CtrlUp}{Delete},ahk_class wndclass_desked_gsk
return

如何获取VBE中的, 鼠标选中文本?

Post by cgx5871 » 26 Jul 2018, 14:12

看了半天Comvar()
还是没搞懂.
有两个需求:
1.我想获取VBA编辑器中, 鼠标选中的代码内容
2. 清空 "立即窗口"
求指导.

Top