I agree it would have made very little difference. Adding the exits as you did was probably the thing which would have best increased its speed. _____ From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx] On Behalf Of Mark Long Sent: 21 May 2010 15:41 To: program-l@xxxxxxxxxxxxx Subject: [program-l] Re: Odd Word Request No doubt - but you would be looking at an improvement of a few milliseconds rather than another order of magnitude. In this case, we probably don't need them sorting anyhow. There is not much point in optimising code that represents a small fraction of the workload and we know that there are fewer than 200 items and more than 80,000 characters to check. I would be happy to see how others would tighten the code still further though. Mark _____ From: dkreynolds@xxxxxxxxxxxx To: program-l@xxxxxxxxxxxxx Subject: [program-l] Re: Odd Word Request Date: Fri, 21 May 2010 14:53:13 +0100 Not exactly the best sorting algorithm I've seen. It is the slowest sorting method, and I'd hazard a guess that if you used something other than bubble, it would run even quicker. _____ From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx] On Behalf Of Mark Long Sent: 21 May 2010 13:04 To: program-l@xxxxxxxxxxxxx Subject: [program-l] Re: Odd Word Request So, probably not worth optimising the sort algorithm then </smile> It is amazing how much difference you can make by removing unnecessary work from an algorythm. Glad that you are pleased. Mark _____ Subject: [program-l] Re: Odd Word Request Date: Fri, 21 May 2010 12:48:53 +0100 From: george@xxxxxxxxxxxxxxxxxxx To: program-l@xxxxxxxxxxxxx Wow! - Did that ever improve performance. It had taken at least 10 minutes previously, but worked in 2-3 seconds with your version. Many thanks indeed, Mark. George. From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx] On Behalf Of Mark Long Sent: 21 May 2010 12:17 To: program-l@xxxxxxxxxxxxx Subject: [program-l] Re: Odd Word Request The code is pretty ineffecient though. Let me see if I can fix that. I haven't tested this but I bet you a pint that it runs in 10% of the time for a non-trivial document. Mark Public Sub ListFontsInDoc() Dim FontList(199) As String Dim FontCount As Integer Dim FontName As String Dim FontNameOfLastChar as String Dim J As Integer, K As Integer, L As Integer Dim X As Long, Y As Long Dim FoundFont As Boolean Dim rngChar As Range Dim strFontList As String FontCount = 0 X = ActiveDocument.Characters.Count Y = 0 FontNameOfLastChar="###" ' no such font ' For-Next loop through every character For Each rngChar In ActiveDocument.Characters Y = Y + 1 FontName = rngChar.Font.Name StatusBar = Y & ":" & X If FontName <> FontNameOfLastChar then ' font has changed FontNameOfLastChar = FontName ' for next time ' check if font used for this char already in list FoundFont = False For J = 1 To FontCount If FontList(J) = FontName Then FoundFont = True Exit For ' no sense looking when we have already found End if Next J If Not FoundFont Then FontCount = FontCount + 1 FontList(FontCount) = FontName End If End if Next rngChar ' sort the list - A shell sort would be better but the list should be small StatusBar = "Sorting Font List" For J = 1 To FontCount - 1 L = J For K = J + 1 To FontCount If FontList(L) > FontList(K) Then L = K Exit For ' Again, no sense in searching when we have already found End if Next K If J <> L Then FontName = FontList(J) FontList(J) = FontList(L) FontList(L) = FontName End If Next J StatusBar = "" ' put in new document Documents.Add Selection.TypeText Text:="There are " & _ FontCount & " fonts used in the document, as follows:" Selection.TypeParagraph Selection.TypeParagraph For J = 1 To FontCount Selection.TypeText Text:=FontList(J) Selection.TypeParagraph Next J End Sub > Subject: [program-l] Re: Odd Word Request > Date: Fri, 21 May 2010 11:30:20 +0100 > From: george@xxxxxxxxxxxxxxxxxxx > To: program-l@xxxxxxxxxxxxx > > By heck, Pranav! It even works! Takes a heck of a while, but > obviously in my case has to look at around 80,000 characters. > > And what's more, I actually managed to do it in that awful Word 2007! > > Bless you, and may all your code compile flawlessly. > > George. > > -----Original Message----- > From: program-l-bounce@xxxxxxxxxxxxx > [mailto:program-l-bounce@xxxxxxxxxxxxx] On Behalf Of Pranav Lal > Sent: 21 May 2010 10:21 > To: program-l@xxxxxxxxxxxxx > Subject: [program-l] Re: Odd Word Request > > George, > > A quick search on the words get list of fonts used in word document > leads me to the following macro from the link > http://word.tips.net/Pages/T001522_Creating_a_Document_Font_List.html. > Public Sub ListFontsInDoc() > Dim FontList(199) As String > Dim FontCount As Integer > Dim FontName As String > Dim J As Integer, K As Integer, L As Integer > Dim X As Long, Y As Long > Dim FoundFont As Boolean > Dim rngChar As Range > Dim strFontList As String > > FontCount = 0 > X = ActiveDocument.Characters.Count > Y = 0 > ' For-Next loop through every character > For Each rngChar In ActiveDocument.Characters > Y = Y + 1 > FontName = rngChar.Font.Name > StatusBar = Y & ":" & X > ' check if font used for this char already in list > FoundFont = False > For J = 1 To FontCount > If FontList(J) = FontName Then FoundFont = True > Next J > If Not FoundFont Then > FontCount = FontCount + 1 > FontList(FontCount) = FontName > End If > Next rngChar > > ' sort the list > StatusBar = "Sorting Font List" > For J = 1 To FontCount - 1 > L = J > For K = J + 1 To FontCount > If FontList(L) > FontList(K) Then L = K > Next K > If J <> L Then > FontName = FontList(J) > FontList(J) = FontList(L) > FontList(L) = FontName > End If > Next J > > StatusBar = "" > ' put in new document > Documents.Add > Selection.TypeText Text:="There are " & _ > FontCount & " fonts used in the document, as follows:" > Selection.TypeParagraph > Selection.TypeParagraph > For J = 1 To FontCount > Selection.TypeText Text:=FontList(J) > Selection.TypeParagraph > Next J > End Sub > > On 5/21/10, George Bell <george@xxxxxxxxxxxxxxxxxxx> wrote: > > Before I start a soul destroying Google search, does anyone know of > a > > quick and easy way to obtain a list of fonts used in a Word 2003 > > Document? > > > > > > > > I have to produce a fairly complex braille mathematics notation > > document, and need to know of any non-standard system fonts used. > > (Aside from 9 specific ones which will be distributed with the > > document). > > > > > > > > This would not be a problem were it not for the fact that even > > embedding of fonts in Word is ignored by the mathematics software > > whose equations are also embedded in the document. > > > > > > > > George. > > > > > > > > > ** To leave the list, click on the immediately-following link:- > ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] > ** If this link doesn't work then send a message to: > ** program-l-request@xxxxxxxxxxxxx > ** and in the Subject line type > ** unsubscribe > ** For other list commands such as vacation mode, click on the > ** immediately-following link:- > ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] > ** or send a message, to > ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq > ** To leave the list, click on the immediately-following link:- > ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] > ** If this link doesn't work then send a message to: > ** program-l-request@xxxxxxxxxxxxx > ** and in the Subject line type > ** unsubscribe > ** For other list commands such as vacation mode, click on the > ** immediately-following link:- > ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] > ** or send a message, to > ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq __________ Information from ESET Smart Security, version of virus signature database 5134 (20100521) __________ The message was checked by ESET Smart Security. http://www.eset.com <http://www.eset.com/> __________ Information from ESET Smart Security, version of virus signature database 5134 (20100521) __________ The message was checked by ESET Smart Security. http://www.eset.com <http://www.eset.com/> __________ Information from ESET Smart Security, version of virus signature database 5135 (20100521) __________ The message was checked by ESET Smart Security. http://www.eset.com <http://www.eset.com/> __________ Information from ESET Smart Security, version of virus signature database 5135 (20100521) __________ The message was checked by ESET Smart Security. http://www.eset.com <http://www.eset.com/> __________ Information from ESET Smart Security, version of virus signature database 5135 (20100521) __________ The message was checked by ESET Smart Security. http://www.eset.com __________ Information from ESET Smart Security, version of virus signature database 5135 (20100521) __________ The message was checked by ESET Smart Security. http://www.eset.com __________ Information from ESET Smart Security, version of virus signature database 5136 (20100521) __________ The message was checked by ESET Smart Security. http://www.eset.com