View Single Post
 
Old 02-29-2024, 07:10 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote