Hallo Scalaia990 ,
Scalaia990 hat geschrieben:kennt jemand eine Möglichkeit wie ich einen ganzen Textblock recht einfach Auskommentieren kann und später wieder aktivieren?
Im englischsprachigen Forum gibt es dazu einen
Code von ms777.
Dieser Code kann aber "nur" auskommentieren.
Ich habe den Code mal übernommen und etwas angepasst, damit er auch in die andere Richtung funktioniert.
Einfach in die Standardbibliothek einfügen und mittels Shortcut oder Schaltfläche ausführen.
Der auszukommentierende Text muss natürlich vorher markiert werden.
Hinweis: Die Markierung muss immer vom Zeilenanfang aus erfolgen, da dort auch das Hochkomma gesetzt wird.
Aber es gilt wie immer, Versuch macht kluch.
Code: Alles auswählen
Sub Comment_Code_Lines
oBasicComp = getBasicWindow
oContWin = oBasicComp.CurrentController.Frame.ComponentWindow
oACScrollPane1 = oContWin.AccessibleContext.getAccessiblechild(0)
oACPanel1 = oACScrollPane1.AccessibleContext.getAccessiblechild(2)
oACPanel2 = oACPanel1.AccessibleContext.getAccessibleChild(4)
oACScrollPane2 = oACPanel2.AccessibleContext.getAccessibleChild(0)
oACTextFrame = oACScrollPane2.AccessibleContext.getAccessibleChild(1)
'oACPara1 = oACTextFrame.AccessibleContext.getAccessibleChild(8)'bringt einen Error
iMaxPara = oACTextFrame.AccessibleContext.AccessibleChildCount-1
aiParaSelected = getSelectedParas(oACTextFrame)
call commentParas(oACTextFrame, aiParaSelected)
End Sub
sub commentParas(oACTextFrame as Any, aiPara as Any)
for k = 0 to UBound(aiPara)
oACP = oACTextFrame.AccessibleContext.getAccessibleChild(aiPara(k))
if left(oACP.Text,1) = "'" then
bResult = oACP.cutText(0,1)
else
bResult = oACP.insertText( "'", 0)
end if
next k
end sub
function getSelectedParas(oACTextFrame as Any) as Any
iMaxPara = oACTextFrame.AccessibleContext.AccessibleChildCount-1
Dim aiParaSelected(iMaxPara) as integer
iCount = 0
for k = 0 to iMaxPara
oACP = oACTextFrame.AccessibleContext.getAccessibleChild(k)
if (oACP.SelectedText = oACP.Text) and (oACP.Text <> "") then
aiParaSelected(iCount) = k
iCount = iCount + 1
endif
next k
if iCount >= 1 then
redim preserve aiParaSelected(iCount-1)
getSelectedParas = aiParaSelected
else
getSelectedParas = Array()
endif
end function
function getBasicWindow() as Any
oEnum = Stardesktop.Components.createEnumeration
while oEnum.hasMoreElements
oComp = oEnum.nextElement
if HasUnoInterfaces(oComp, "com.sun.star.lang.XServiceInfo") then 'to cath the Help Window
if oComp.supportsService("com.sun.star.script.BasicIDE") then
oBasicComp = oComp
endif
endif
wend
getBasicWindow = oBasicComp
end function
Jürgen