Sub 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 Set cpa = VBInstance.ActiveCodePane Set cmo = cpa.CodeModule If Err Then Exit Sub cpa.GetSelection startLine, startCol, endLine, endCol If startLine = endLine And startCol = endCol Then Exit Sub If startLine = endLine Then codeText = cmo.Lines(startLine, 1) Mid$(codeText, startCol, endCol - startCol) = StrConv(Mid$(codeText, _ startCol, endCol - startCol), conversion) cmo.ReplaceLine startLine, codeText Else 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 For i = startLine + 1 To endLine - 1 codeText = cmo.Lines(i, 1) codeText = StrConv(codeText, conversion) cmo.ReplaceLine i, codeText Next codeText = cmo.Lines(endLine, 1) Mid$(codeText, 1, endCol - 1) = StrConv(Mid$(codeText, 1, endCol - 1), _ conversion) cmo.ReplaceLine endLine, codeText End If cpa.SetSelection startLine, startCol, endLine, endCol End Sub |