A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi,
We can convert string of Worksheet name to object because it's hard to convert string of Worksheet code name.
Here's some codes for you, please copy them to a Module.
Option Explicit
Public ws As Worksheet
Sub UDF(WrkshtName)
If VarType(WrkshtName) = vbString Then
Set ws = Sheets(WrkshtName)
ElseIf VarType(WrkshtName) = vbObject Then
Set ws = WrkshtName
End If
End Sub
Sub TestForConvertingStringToOjbect()
Call UDF("Sheet1") 'Here the parameter 'Sheet1' is a Worksheet name.
MsgBox ws.CodeName, vbInformation, "String to Object"
End Sub
Sub TestForObject()
Call UDF(Sheet1) 'Here the parameter 'Sheet1' is a code name of Worksheet.
MsgBox ws.CodeName, vbInformation, "Direct Use of Ojbect"
End Sub
The above two macros('TestForConvertingStringToOjbect' and 'TestForObject') will show you the result.
Hope this help you.