#1
|
|||
|
|||
How is a variant array created to pass properties to a style?
How do I create a variant array to pass multiple properties of different data types to a style?
I recorded a macro that modifies all nine multilevel-list-style levels. It's long/repetitive, I'll need to do the same to other multilevel list styles, so I'm trying to streamline it. The macro revises 10 properties in each level: some are strings, others are numeric (exact types are in the code). Putting them in a delimited string, splittling (which only works with string arrays), then converting to a variant array doesn't work -- looks like the variant array is an exact copy of the string array. The attached file also includes the following code, plus some text with the multilevel-list style applied. The macro is shorter than it looks -- I commented the heck out of it because...terrible memory. And it doesn't loop yet because...this forum question. Code:
Sub SpecTemplate_ConvertMultilevelListStyle_6() ' 09/04/2021 ' This macro: ' 1 Converts a string of level properties for a multilevel-list style to an array ' 2 Converts the string array to a variant array ' 3 Applies the level properties to a level style Dim strStyleName As String Dim arr_Str_PropertiesFromString() As String ' Can't use Split function to create variant array, so use a string- ' type array as prelim step to getting properties into a variant array Dim arr_Var_LevelProperties() As Variant ' Use variant array to receive initial string array and apply properties Dim lngIndex As Long ' Array index for copying string array to variant array ' Populate initial string array: arr_Str_PropertiesFromString = Split("""%1""|wdTrailingTab|wdListNumberStyleArabic|0|wdListLevelAlignLeft|0.5|0.5|0|1|""Heading 1""", "|") ' ReDim variant array to same size as string array: ReDim arr_Var_LevelProperties(LBound(arr_Str_PropertiesFromString) To UBound(arr_Str_PropertiesFromString)) ' Put string array into variant array: For lngIndex = LBound(arr_Str_PropertiesFromString) To UBound(arr_Str_PropertiesFromString) arr_Var_LevelProperties(lngIndex) = arr_Str_PropertiesFromString(lngIndex) Next lngIndex For lngIndex = LBound(arr_Var_LevelProperties) To UBound(arr_Var_LevelProperties) Debug.Print arr_Var_LevelProperties(lngIndex) Next ' Update a specific multilevel list style strStyleName = "Spec List Style" With ActiveDocument.Styles("Spec List Style").ListTemplate.ListLevels With .Item(1) ' DATA TYPE: .NumberFormat = arr_Var_LevelProperties(0) ' 8 (String) .TrailingCharacter = arr_Var_LevelProperties(1) ' 3 (Long Integer) .NumberStyle = arr_Var_LevelProperties(2) ' 3 (Long Integer) .NumberPosition = InchesToPoints(arr_Var_LevelProperties(3)) ' 4 (Single-precision floating-point number) .Alignment = arr_Var_LevelProperties(4) ' 3 (Long Integer) .TextPosition = InchesToPoints(arr_Var_LevelProperties(5)) ' 4 (Single-precision floating-point number) .TabPosition = InchesToPoints(arr_Var_LevelProperties(6)) ' 4 (Single-precision floating-point number) .ResetOnHigher = arr_Var_LevelProperties(7) ' 3 (Long Integer) .StartAt = arr_Var_LevelProperties(8) ' 3 (Long Integer) .LinkedStyle = "Heading 1" ' arr_Var_LevelProperties(9) ' 8 (String) End With End With End Sub |
#2
|
||||
|
||||
It is normally done with user-defined data types. This requires waaay more lines of code to implement though.
See Type statement (VBA) | Microsoft Docs for a very brief example
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Thanks for the reply, Andrew. I'll stick to the long but functional version of the macro I started with.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Export properties of a given Style. | mc1903 | Word VBA | 2 | 01-17-2019 08:35 AM |
Style Window Doesn't Display a Style that I Created | Editor | Word | 6 | 10-28-2013 10:51 AM |
An array of words from a document knowing the font style | Kreol2013 | Word VBA | 0 | 07-08-2013 01:29 AM |
Convert String Array to Integer Array from a User Input? | tinfanide | Excel Programming | 4 | 12-26-2012 08:56 PM |
how can i make random variant | neezeen | Word | 0 | 11-22-2011 08:08 AM |