Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2021, 11:59 AM
Peterson Peterson is offline How is a variant array created to pass properties to a style? Windows 10 How is a variant array created to pass properties to a style? Office 2019
Competent Performer
How is a variant array created to pass properties to a style?
 
Join Date: Jan 2017
Posts: 141
Peterson is on a distinguished road
Default 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
Attached Files
File Type: docm Spec Template_Rebuild_13.docm (39.3 KB, 6 views)
Reply With Quote
  #2  
Old 09-06-2021, 04:39 PM
Guessed's Avatar
Guessed Guessed is offline How is a variant array created to pass properties to a style? Windows 10 How is a variant array created to pass properties to a style? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 09-06-2021, 05:52 PM
Peterson Peterson is offline How is a variant array created to pass properties to a style? Windows 10 How is a variant array created to pass properties to a style? Office 2019
Competent Performer
How is a variant array created to pass properties to a style?
 
Join Date: Jan 2017
Posts: 141
Peterson is on a distinguished road
Default

Thanks for the reply, Andrew. I'll stick to the long but functional version of the macro I started with.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How is a variant array created to pass properties to a style? Export properties of a given Style. mc1903 Word VBA 2 01-17-2019 08:35 AM
How is a variant array created to pass properties to a style? 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
How is a variant array created to pass properties to a style? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:16 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft