¿Puedo declarar y asignar simultáneamente una variable en VBA?


Soy nuevo en VBA y quiero saber si puedo convertir la siguiente declaración y asignación en una línea:

Dim clientToTest As String
clientToTest = clientsToTest(i)

O

Dim clientString As Variant
clientString = Split(clientToTest)
Author: ashleedawg, 2010-07-15

3 answers

No hay taquigrafía en VBA desafortunadamente, lo más cercano que obtendrá es una cosa puramente visual usando el carácter de continuación : si lo desea en una línea para facilitar la lectura;

Dim clientToTest As String:  clientToTest = clientsToTest(i)
Dim clientString As Variant: clientString = Split(clientToTest)
 185
Author: Alex K.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-07-15 14:10:26

Puede hacer eso con objetos, como en el siguiente.

Dim w As New Widget

Pero no con cadenas o variantes.

 14
Author: John M Gant,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-07-15 14:18:23

De hecho, se puede, pero no de esa manera.

Sub MySub( Optional Byval Counter as Long=1 , Optional Byval Events as Boolean= True)

'code...

End Sub

Y puede establecer las variables de manera diferente al llamar al sub, o dejarlas en sus valores predeterminados.

 0
Author: Patrick Lepelletier,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-07 20:56:39