'
' UnHide All hidden rows Macro
'
' Macro created 13-2-2006 by Bob Becker Hof (HP)
' Tested with Excel 2003 and EVE 2.30 xls output format
' Changed Row and Column variables from Integer to Long to avoid Overflow if more then 32767 rows
' Moved the real code to a function which is called by the original (sub) macro. The sub will call the function
' 	with a parameter "Interactive". The function itself does nothing with it but. It has been splitted to make it conform the other 
'		macros. Nothing more.
' Changed the selection as the first row could also be hidden
' Fixed the lasrow determination
' Taking care of proper comment text sizing when we return from hiding
' Now unhiding while using a range instead of a slection as that is faster
'

Sub UnHideAllRows()
		Function_UnHideAllRows("Interactive")
End Sub

Function Function_UnHideAllRows(mode)
Dim crow As Long
Dim ccol As Long
Dim lasrow As Long
Dim lascol As Long
Dim hidden_rows_behind_lasrow As Long

    crow = ActiveCell.Row
    ccol = ActiveCell.Column
    lasrow = ActiveCell.SpecialCells(xlLastCell).Row
    lascol = ActiveCell.SpecialCells(xlLastCell).Column
    
'
' By default the xlLastCell.row funtion returns the last visible row
' But there might be more rows below it which are hidden so loop down until we hit a row which is NOT hidden
' Lets assume that 650000 is the maximum row number possible...
'
''    Debug.Print "Current Lasrow: " & Str(lasrow)
    For hidden_rows_behind_lasrow = lasrow To 650000 Step 1
        If Not (Range(Cells(hidden_rows_behind_lasrow + 1, 1).Address).EntireRow.Hidden) Then
            lasrow = hidden_rows_behind_lasrow
''            Debug.Print "New Lasrow    : " & Str(lasrow)
            Exit For
        End If
    Next
    
    newrange = "1:" + Trim(Str(lasrow))
    Range(newrange).EntireRow.Hidden = False

'
' Autosize all comment shapes
'

    For Each rng In ActiveSheet.Comments
        
        rng.Shape.Top = rng.Parent.Top + 5
        rng.Shape.Left = _
                rng.Parent.Offset(0, 1).Left + 5
        With rng
            .Shape.Placement = xlMoveAndSize
            .Shape.TextFrame.AutoSize = True
''            .Shape.Visible = True
            If .Shape.Width > 300 Then
                lArea = .Shape.Width * .Shape.Height
                .Shape.Width = 200
                ' An adjustment factor of 1.1 seems to work ok.
                .Shape.Height = (lArea / 200) * 1.1
            End If
        End With
    Next

    Cells(crow, ccol).Select

End Function
