Why it works only on the first iteration?

Thread Starter

Shafty

Joined Apr 25, 2023
327
Code:
Sub Operation_PWA_Members()
Dim xlApp As New Excel.Application
xlApp.Visible = True
Dim xlSheet As Worksheet
Set xlSheet = xlApp.Workbooks.Open(Replace(ThisDocument.Path & "\" & ThisDocument.Name, "docm", "xlsm")).Worksheets(1)
With xlSheet
    .Range("A1").Value = "Font_Name"
    For Each Character In ThisDocument.Characters
        With Character
            Dim ArrayFromFilter As Variant
            ArrayFromFilter = Filter(Array(xlSheet.UsedRange.Value), .Font.Name)
            If Not IsEmpty(ArrayFromFilter) Then
                xlSheet.Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0).Value = .Font.Name
            End If
        End With
    Next Character
End With
End Sub
How to make it work on the following iterations too... Please Help.

With Hope,
Prabhakaran

p.s:
I am getting a 'Type-Mismatch' Error from the 2nd iteration itself.
 

wayneh

Joined Sep 9, 2010
18,104
I'd try adding logging statements so you can see the results of each step. I use the Application.StatusBar mostly but MsgBox is OK too.
 

Thread Starter

Shafty

Joined Apr 25, 2023
327
There is a word document presently typed in our mother tongue (Tamil) but by using different encoding methods at different places.
My Goal is to convert the whole document in Unicode.
That's why First I am making list of fonts used in the present document. To make a list in excel (unique list) we need to know whether the current character's font is already listed or not. That's why Filter Function.
Filter function (Visual Basic for Applications) | Microsoft Learn
 

Thread Starter

Shafty

Joined Apr 25, 2023
327
Code:
Dim ArrayFromFilter As Variant
ArrayFromFilter = Filter(Array(xlSheet.UsedRange.Value), .Font.Name)
2nd line in 2nd iteration throws 'Type-Mismatch'
 

wayneh

Joined Sep 9, 2010
18,104
Use the logging statements to output the value of, for instance, Array(xlSheet.UsedRange.Value). You need to find where a value is not what you expect, and is thus throwing the mismatch error.
 
Top