View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default RowHeight and AutoFit wit Merged Cells

"Howard Kaikow" wrote in message
...
When you run the code, are you running via VB 6, or are you running in
Excel?


In Word. I 've just repeated in VB6 and got similar timings. However, seems
it depends on what you are doing as to whether there's a significant speed
gain with screenupdating disabled when excel is not visible.

Try the following in Word or VB6 and have a cup of coffee, or even a glass
of OJ. For me a significant saving with bAutoFitTest = false but not much in
the second loop when bAutoFitTest = True

Option Explicit
Sub xlScrnUpdate()
Dim bAutoFitTest As Boolean
Dim i As Long
Dim t As Single
Dim oRng As Object
Dim oWS As Object
Dim xlApp As Object

Set xlApp = CreateObject("excel.application")
Set oWS = xlApp.workbooks.Add.worksheets(1)

For i = 0 To 1

bAutoFitTest = i = 1
Debug.Print bAutoFitTest

xlApp.Visible = False
xlApp.ScreenUpdating = True
testStuff oWS, bAutoFitTest

xlApp.ScreenUpdating = False
testStuff oWS, bAutoFitTest

xlApp.Visible = True
xlApp.ScreenUpdating = True
testStuff oWS, bAutoFitTest

xlApp.ScreenUpdating = False
testStuff oWS, bAutoFitTest
Next
xlApp.ScreenUpdating = True

Stop

oWS.Parent.Close 0
Set oWS = Nothing
xlApp.Quit
Set xlApp = Nothing
Unload Me

End Sub

Sub testStuff(oWS As Object, bColWidth As Boolean)
Dim i As Long, qty As Long
Dim t As Single

If bColWidth Then qty = 2000 Else qty = 10000

oWS.Cells.clearcontents
With oWS.Columns(1)
.columnwidth = .Parent.standardwidth
t = Timer
For i = 1 To qty
.Cells(i, 1) = i & " some text longish text " & i
If bColWidth Then
.entirecolumn.AutoFit
End If
Next
End With
t = Timer - t
Debug.Print t
End Sub

Private Sub Form_Load()
xlScrnUpdate
End Sub

Regards,
Peter T