29. januar 2010 - 12:28Der er
4 kommentarer og 1 løsning
VBA global variabel
Hej Eksperter
Hvordan laver jeg en global variabel i en funktion i VBA?
Har prøvet ALT
Her er et eksempel
' Test_String Public Function MyString() As String Dim invDoc As String Set invDoc = "Test" End Function
Public Function MyBool() As String Dim invDoc As Boolean Set invDoc = true End Function
Jeg kan ikke definere variablen uden for funktionen da jeg ikke ved på det tidspunkt om det er en String eller Bool. Hvordan kommer jeg rundt om dette problem?
Sub tester() Dim modtager As Variant modtager = variantTest(True)
modtager = variantTest(False) End Sub Function variantTest(StringEllerBoolean) If StringEllerBoolean = True Then variantTest = True Else variantTest = "Test" End If End Function
Vedr. dit spørgsmål: Fra Hjælp til VARIANT(Fra VBA/Excel)
The Variant data type is the data type for all variables that are not explicitly declared as some other type (using statements such as Dim, Private, Public, or Static). The Variant data type has no type-declaration character.
A Variant is a special data type that can contain any kind of data except fixed-length String data. (Variant types now support user-defined types.) A Variant can also contain the special values Empty, Error, Nothing, and Null. You can determine how the data in a Variant is treated using the VarType function or TypeName function.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.