Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-17-2023, 08:56 AM
TheBigBoss TheBigBoss is offline Select Lists or List.ListParagraphs of bulleted text Windows 10 Select Lists or List.ListParagraphs of bulleted text Office 2016
Advanced Beginner
Select Lists or List.ListParagraphs of bulleted text
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default Select Lists or List.ListParagraphs of bulleted text

Hello,

I struggle to select the numbered items of a custom list (1., 2., (a), etc.).

The aim here is to select all numbers items and change font to Times New Roman.
.dotm is attached to test



I tried this but it fails
Code:
Public Sub ChineseChar()
    Dim oD As Object, i As Integer, lstp As List
    Set oD = ActiveDocument
    If (Selection.Type <> wdSelectionIP) Then
        Selection.Font.Name = "Times New Roman"
        MsgBox "Times New Roman has been applied to the selected text"
    Else
        oD.Select
        Selection.WholeStory
        Selection.Font.Name = "Times New Roman"
       
        For Each lstp In oD.Lists
            lstp.Range.Font.Name = "Times New Roman"
        Next lstp
    End If
    Exit Sub
End Sub
Attached Files
File Type: dotm CHINESE.dotm (27.0 KB, 0 views)
Reply With Quote
  #2  
Old 02-17-2023, 12:06 PM
TheBigBoss TheBigBoss is offline Select Lists or List.ListParagraphs of bulleted text Windows 10 Select Lists or List.ListParagraphs of bulleted text Office 2016
Advanced Beginner
Select Lists or List.ListParagraphs of bulleted text
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default

Found the solution, almost...
Code:
Sub SelectNumberingAndChangeFont()
    Dim para As Paragraph
    Dim list As list
    Dim lvl As ListLevel
    Dim lev As ListTemplate
    
    For Each lev In ActiveDocument.ListTemplates
        For Each lvl In lev.ListLevels
                lvl.Font.Name = "Times New Roman"
            Next lvl
    Next lev
End Sub
Now the tricky part, it shouldn't changed to Times New Roman for the third-level (third-level should remain SimSun). Using ListIndex returns the index not the level; how to know the level of the list from ListLevels?


Code:
Sub SelectNumberingAndChangeFont()
    Dim para As Paragraph
    Dim list As list
    Dim lvl As ListLevel
    Dim lev As ListTemplate
    
    For Each lev In ActiveDocument.ListTemplates
        For Each lvl In lev.ListLevels
           If lvl.Index <> 3 Then
           'If lvl.LevelNumber <> 3 Then
                lvl.Font.Name = "Times New Roman"
            End If
            Next lvl
    Next lev
End Sub
Reply With Quote
  #3  
Old 02-19-2023, 12:51 AM
TheBigBoss TheBigBoss is offline Select Lists or List.ListParagraphs of bulleted text Windows 10 Select Lists or List.ListParagraphs of bulleted text Office 2016
Advanced Beginner
Select Lists or List.ListParagraphs of bulleted text
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default

So the solution here would be to:

a) To loop through each paragraph, verify it is a paragraph with levels (list), create an array of paragraph index when level is the third level
Code:
For Each para In ActiveDocument.ListParagraphs
        If para.Range.ListFormat.ListType <> wdListNoNumbering Then
b) To use the macro above, but if lvl.Index is found in array, then don't change to Times New Roman.
Code:
For Each lev In ActiveDocument.ListTemplates
        For Each lvl In lev.ListLevels
           If lvl.Index (found in array) Then
It seems it is possible to determine the level of the list using ListLevels or ListTemplates.
The only way to know level of list is through ListFormat properties (.ListLevelNumber, .ListString and .ListValue)
Reply With Quote
  #4  
Old 02-19-2023, 01:40 AM
TheBigBoss TheBigBoss is offline Select Lists or List.ListParagraphs of bulleted text Windows 10 Select Lists or List.ListParagraphs of bulleted text Office 2016
Advanced Beginner
Select Lists or List.ListParagraphs of bulleted text
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default

I give up... I failed.

Attached is the macro with console log.
I only want to change ActiveDocument.ListTemplates.ListLevels.Font.Name = "Times New Roman" at exception of third-level paragraph.

Sounds I need an expert here, thanks
Attached Files
File Type: dotm CHINESE.dotm (30.5 KB, 2 views)
Reply With Quote
  #5  
Old 02-19-2023, 07:54 PM
Guessed's Avatar
Guessed Guessed is offline Select Lists or List.ListParagraphs of bulleted text Windows 10 Select Lists or List.ListParagraphs of bulleted text Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
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

Perhaps this is what you wanted
Code:
Sub ChangeListFonts()
  Dim aLT As ListTemplate, aLL As ListLevel
  For Each aLT In ActiveDocument.ListTemplates
    For Each aLL In aLT.ListLevels
      If aLL.Index <> 3 Then
        aLL.Font.Name = "Times New Roman"
      End If
    Next aLL
  Next aLT
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #6  
Old 02-19-2023, 11:04 PM
TheBigBoss TheBigBoss is offline Select Lists or List.ListParagraphs of bulleted text Windows 10 Select Lists or List.ListParagraphs of bulleted text Office 2016
Advanced Beginner
Select Lists or List.ListParagraphs of bulleted text
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default

Hi Guessed, I posted a similar code above, it doesn't as Index doesn't return the level but just the index.

I found the solution to detect third-level using ListTemplates.ListLevels.
I use TextPosition. Since the list styles are well defined, the TextPosition is fixed and well known.

Code:
Sub SelectNumberingAndChangeFont()
    Dim para As Paragraph
    Dim list As list
    Dim lvl As ListLevel
    Dim lev As ListTemplate
    Dim i As Integer
    Dim ib As Integer
    i = 0
    ib = 0
    For Each lev In ActiveDocument.ListTemplates
        For Each lvl In lev.ListLevels
            Debug.Print "TXT POS - " & lvl.TextPosition
            If lvl.TextPosition <> 147.4 Then
                 lvl.Font.Name = "Times New Roman"
                ' Change numbering of list to Times New Roman at the exception of third-level numbering
            End If
            Next lvl
    Next lev
End Sub
Closing thread
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Lists or List.ListParagraphs of bulleted text autoformat bulleted lists tlstaylorgirl Word 1 09-17-2015 12:12 PM
Bulleted Lists in Notebook Layout beatles1291 Word 0 01-25-2012 08:52 PM
Adjust list indents for all bulleted text (of different bullets) ghumdinger Word 13 09-21-2011 12:59 AM
Bulleted and Numbered Lists peret944 Word 0 03-25-2011 01:08 PM
Select Lists or List.ListParagraphs of bulleted text Bulleted Lists - Changing Font mhartman09 Word 2 12-10-2010 12:18 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:17 AM.


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