任何人都可以在VBA中提供帮助吗? [英] Anyone can help in VBA ?
本文介绍了任何人都可以在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 useSelect 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)
这篇关于任何人都可以在VBA中提供帮助吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文