View Single Post
 
Old 05-10-2018, 06:56 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

Just tidying the logic a little bit and changing the activewindow view. Is this any different in speed?
Code:
Sub SpeedTest()
  Dim oShp As Shape, changecount As Integer, shapecount As Long, shapemax As Long
  Dim timestart As Date, timestop As Date, changeflag As Boolean
    
  timestart = Now()
  shapemax = ActiveDocument.Shapes.Count
  
  Application.ScreenUpdating = False
  ActiveWindow.View = wdNormalView
  changeflag = False
    
  For Each oShp In ActiveDocument.Shapes
    changeflag = False
    If oShp.AlternativeText = "shrink" Then
      With oShp.TextFrame
        Do While .Overflowing
          changeflag = True
          .TextRange.Font.Shrink
          DoEvents
        Loop
      End With
      If changeflag = True Then changecount = changecount + 1
      StatusBar = String(50, " ") & "Macro status: " & shapecount & " of " & AllShapes
      shapecount = shapecount + 1
    End If
  Next oShp
  
  ActiveWindow.View = wdPrintView
  Application.ScreenUpdating = True
  timestop = Now()
  MsgBox "Complete - " & changecount & " changes made. Time taken: " & DateDiff("s", timestart, timestop) & " seconds"
End Sub
Note that dimensioning without an explicit type gives you a variant. For example,
Dim shapecount, shapemax As Long
gives you shapecount as a variant and shapemax as Long
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote