View Single Post
 
Old 03-05-2024, 10:06 AM
viewtost viewtost is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jul 2021
Posts: 35
viewtost is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
A variant variable can hold strings. An array of strings e.g., Dim ctrlTitle() as String cannot resolve a variant array.


Consider:
Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim strVar() As String 'Here we have declared a string variable as an array of strings
Dim strVar2 As String
Dim varVar 'Here we have declared a variant variable
Dim lngNum As Long
  strVar = Split("A,B,C", ",")
  'A variant variable can be a string
  varVar = strVar
  'Here we set our variant variable to the variant returned by the Array funciton
  varVar = Array("A", 1, "C", 2.4)
  'While some other variable types are automatically resolved e.g., ...
  lngNum = 100
  strVar2 = lngNum
  '... a variant array cannot be resolved to a string
  On Error GoTo Err_Handler
  strVar = varVar
lbl_Exit:
  Exit Sub
Err_Handler:
  MsgBox "Do you see?"
  Resume lbl_Exit
End Sub
Understood, many thanks!
Reply With Quote