任何人都可以在VBA中提供帮助吗?

问题描述:

如何使用以下代码?
我想选择大小写



How to use this below code ?
i want to select case



Sub SelectedWoksheets()
'http://www.ozgrid.com/VBA/excel-vba-sheet-names.htm
Dim ws As Worksheet

    For Each ws In ActiveWindow.SelectedSheets
        With ws
        
            'With Code Here
        
        End With
    Next ws
End Sub



添加了代码块[/编辑]



Code block added[/Edit]

如果我对您的理解很好,则想使用Select Case ... End Select语句.
If i understand you well, you want to use Select Case ... End Select statement.
Select case ws.Name
    Case "Sheet1"
        'do something
    Case "Sheet2"
        'do something
    Case "Sheet3"
        'do something
    Case Else
        'do something
End Select



但是,如果要浏览工作表的集合以通过其名称查找"正确的工作表,则最好使用如下所示的方法:



But if would like to go through the collection of worksheets to "find" the correct one by its name, better use something like this:

Function GetWoksheet(wshName As String, wbk As Workbook) As Worksheet
Dim wsh As Worksheet

On Error Goto Err_GetWoksheet

Set wsh = wbk.Workseets(wshName)

Exit_GetWoksheet:
    Set GetWoksheet = wsh
    Exit Function

Err_GetWoksheet:
    MsgBoxErr.Description, vbExclamation, Err.Number
    Set wsh = Nothing
    Resume Exit_GetWoksheet

End Function



用法:



Usage:

Set wsh =  GetWoksheet("Sheet4", ActiveWorkbook)