ConvertSelectedTex – Convert text selected in code window

ConvertSelectedTex – Convert text selected in code window

' Convert to uppercase, lowercase, or propercase the text that is' currently selected in the active code windowSub ConvertSelectedText(VBInstance As VBIDE.VBE, Optional conversion As Long = _    vbUpperCase)    Dim startLine As Long, startCol As Long    Dim endLine As Long, endCol As Long    Dim codeText As String    Dim cpa As VBIDE.CodePane    Dim cmo As VBIDE.CodeModule    Dim i As Long       On Error Resume Next       ' get a reference to the active code window and the underlying module    ' exit if no one is available    Set cpa = VBInstance.ActiveCodePane    Set cmo = cpa.CodeModule    If Err Then Exit Sub       ' get the current selection coordinates    cpa.GetSelection startLine, startCol, endLine, endCol    ' exit if no text is highlighted    If startLine = endLine And startCol = endCol Then Exit Sub       ' get the code text    If startLine = endLine Then        ' only one line is partially or fully highlighted        codeText = cmo.Lines(startLine, 1)        Mid$(codeText, startCol, endCol - startCol) = StrConv(Mid$(codeText, _            startCol, endCol - startCol), conversion)        cmo.ReplaceLine startLine, codeText    Else        ' the selection spans multiple lines of code        ' first, convert the highlighted text on the first line        codeText = cmo.Lines(startLine, 1)        Mid$(codeText, startCol, Len(codeText) + 1 - startCol) = StrConv(Mid$ _            (codeText, startCol, Len(codeText) + 1 - startCol), conversion)        cmo.ReplaceLine startLine, codeText               ' then convert the lines in the middle, that are fully highlighted        For i = startLine + 1 To endLine - 1            codeText = cmo.Lines(i, 1)            codeText = StrConv(codeText, conversion)            cmo.ReplaceLine i, codeText        Next              ' finally, convert the highlighted portion of the last line        codeText = cmo.Lines(endLine, 1)        Mid$(codeText, 1, endCol - 1) = StrConv(Mid$(codeText, 1, endCol - 1), _            conversion)        cmo.ReplaceLine endLine, codeText    End If       ' after replacing code we must restore the old selection    ' this seems to be a side-effect of the ReplaceLine method    cpa.SetSelection startLine, startCol, endLine, endColEnd Sub

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of