VBA Dim multiple variables syntax.

Posted on 2009/02/26

0


I was recently tinkering with an Excel macro, written in Visual Basic for Applications. The following error occurred:

ByRef Argument Type Mismatch

I always put Option Explicit at the beginning of each VBA module, in order to minimize errors related to variable types. The error highlights a call to a function that has var1 as a parameter, and var1 is declared as:

Dim var1, var2 As String

Turns out, var1 is not a string. I assumed that this notation declared both var1 and var2 as strings, but that’s not the case in VBA. I corrected the code:

Dim var1 As String, var2 As String

This page helped me.

add to del.icio.us :: Bookmark Post in Technorati :: Add to Blinkslist :: add to furl :: Digg it :: add to ma.gnolia :: Stumble It! :: add to simpy :: seed the vine :: :: :: TailRank :: post to facebook :: Bookmark on Google :: Add to Netscape :: Share on Yahoo :: Add this to Live

About these ads
Posted in: Software