Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90214

How to stop Excel VBA from renaming variables and parameters in unrelated modules and methods?

$
0
0

I noticed unbelievable destructive behavior of Excel VBA. It silently and automatically renames variables and function parameters in unrelated modules when I add, say, a new property to class. Observed on Office Professional Plus 2016 and Windows 10.

For concrete example, I have one module and one class. Module looks like this:

Private Function MyRequests() As Collection
    Dim requests As Collection
    Set requests = New Collection
    Dim row As Integer
    row = 3
    Dim oRequest As New MyRequest
    oRequest.Name = "SomeName"
    requests.Add oRequest
    MyRequests = requests
End Function

Class MyRequest looks like this:

Private sName As String

Property Let Name(sValue As String)
    sName = sValue
End Property

Now the unbelievable part comes. I add new property to the MyRequest class:

Private iRow As Integer

Property Let Row(iValue As Integer)
    iRow = iValue
End Property

I save code, go to module and its private function which now looks like this:

Private Function MyRequests() As Collection
    Dim requests As Collection
    Set requests = New Collection
    Dim Row As Integer
    Row = 3
    Dim oRequest As New MyRequest
    oRequest.Name = "SomeName"
    requests.Add oRequest
    MyRequests = requests
End Function

Notice that row became Row! This silent auto-renaming also happens throughout the VBA code in sheets... Basically everywhere, Excel renamed row to Row!

So, my question is what can I do to stop this insane behaviour?


Viewing all articles
Browse latest Browse all 90214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>