try it
Sub Sample() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("MySheet") With ws MySub ws '~~> Rest of the code End With End Sub
or
Sub Sample() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("MySheet") MySub ws With ws '~~> Rest of the code End With End Sub
Edit
Do you have any information about the existence of "this"? - deathApril 19 minutes ago
this is basically a keyword from C # that refers to the current instance of the class. The equivalent of this in VB is Me .
The Me keyword provides a way to access a specific instance of the class or structure in which the code is currently executing . For example, in Userform you can use
Me.textBox1.Text = "Blah Blah"
In VBA, Me can also be used for thisworkbook . For example, if you paste this code into the code area of thisworkbook , it will give you the name of the book
Sub Sample() Debug.Print Me.Name End Sub
Similarly, when you run the above code from the sheet code area, you will get the sheet name.
NTN
source share