みんな! ユーザーフォームは、大文字、小文字または適切な機能を使用してテキストを変更する
私の最初のコードがあれば使用
- 大文字
- 小文字を:私は3つのオプションを使用して私のテキストの文字を変更するには、ユーザーフォームを作成した。このとき
- それでは構造は大丈夫だった。私は以下にそれを置く:
Private Sub OkButton_Click() Dim WorkRange As Range Dim cell As Range 'Detects only constant type (text; excludes formulas) On Error Resume Next Set WorkRange = Selection.SpecialCells(xlCellTypeConstants, xlCellTypeConstants) 'Uppercase If OptionUpper Then For Each cell In WorkRange cell.Value = UCase(cell.Value) Next cell End If 'Uppercase If OptionLower Then For Each cell In WorkRange cell.Value = LCase(cell.Value) Next cell End If 'Using Proper Function If OptionProper Then For Each cell In WorkRange cell.Value = Application.WorksheetFunction.Proper(cell.Value) Next cell End If Unload UserForm1 End Sub Private Sub UserForm_Click() End Sub
私はUserForm1での実行にモードを使用:
Sub ChangeCase2() If TypeName(Selection) = "Range" Then UserForm1.Show Else MsgBox "Selection a range.", vbCritical End If End Sub
そして、すべてがうまく働きました。しかし、私は考えました:Select Case構造を使用することは可能でしょうか?だから私は試してみましたが、残念ながら走っていませんでした。大文字オプションは小文字として機能し、小文字と小文字は大文字として機能します。私はボタンに付けたキャプションを見直しました。私を助けてくれますか?
Private Sub CancelButton_Click() Unload UserForm2 End Sub Private Sub OkButton_Click() Dim WorkRange As Range Dim cell As Range Dim OptionSelect As Variant On Error Resume Next Set WorkRange = Selection.SpecialCells(xlCellTypeConstants, xlCellTypeConstants) Select Case OptionSelect Case OptionUpper 'Letras Maiúsculas For Each cell In WorkRange cell.Value = UCase(cell.Value) Next cell Case OptionLower 'Letras Minúsculas For Each cell In WorkRange cell.Value = LCase(cell.Value) Next cell Case OptionProper 'Iniciais Maiúsculas For Each cell In WorkRange cell.Value = Application.WorksheetFunction.Proper(cell.Value) Next cell End Select Unload UserForm2 End Sub
私はUserForm2に別のモードを使用:
Sub ChangeCase3() If TypeName(Selection) = "Range" Then UserForm2.Show Else MsgBox "Selection a range.", vbCritical End If End Sub
に対してOptionButtonsの値と一致するように適切な値を与えます、 'OptionLower'または' OptionProper'? 'Dim OptionSelect As Variant'という行を追加したので、値が魔法のように表示されると思いますか? –
それは愚かな間違いだったようです。私はVBAで初心者ですが、私はまだあなたのコミットメントに感謝します。おかげで – netuno26