davehill01
New Member
- Joined
- Jun 22, 2012
- Messages
- 10
Hi all
I have a 2003 macro which I inherited from someone else. In theory I believe it should run in 2007.
But when I run it I get the following error message.
Run-time error '445'
Object doesn't support this action
Here's the macro.
Can anyone help me to get it working please.
Thanks in advance
Dave
Option Explicit
Public Enum ExcelVersion
Excel2000
Excel2002
Excel2003
Excel2007
Excel2010
Unknown
End Enum
Function CheckExcelVersion() As ExcelVersion
'Check the Excel Version
Select Case Application.Version
Case "9.0"
CheckExcelVersion = Excel2000
Case "10.0"
CheckExcelVersion = Excel2002
Case "11.0"
CheckExcelVersion = Excel2003
Case "12.0"
CheckExcelVersion = Excel2007
Case "14.0"
CheckExcelVersion = Excel2010
Case Else
CheckExcelVersion = Unknown
End Select
End Function
Public Sub Run_Spreadsheet_Compare(Optional Session As String = "")
Dim fMain As New frmMain
fMain.OpenSession = Session
fMain.Show vbModal
'frmMain.Show vbModal
End Sub
Sub Run_SyncScroll()
Dim ApplicationVersion As ExcelVersion
ApplicationVersion = CheckExcelVersion()
'Feature added in Excel 2003
If ApplicationVersion >= Excel2003 Then
Dim Window1 As Window
Dim Window2 As Window
If Windows.Count < 2 Then
MsgBox "Need two Windows open to synchronise scrolling", vbExclamation
Exit Sub
End If
'Disable side by side
'Windows.BreakSideBySide
CallByName Windows, "BreakSideBySide", VbMethod
'Set the two windows to make side by side
Set Window1 = ActiveWindow
If Windows(1).Caption = Window1.Caption Then
Set Window2 = Windows(2)
Else
Set Window2 = Windows(1)
End If
'Normalise 2nd Window
Window2.Zoom = Window1.Zoom
Window2.Activate
Window2.ScrollRow = 1
Window2.ScrollColumn = 1
'Normalise 1st window
Window1.Activate
Window1.ScrollRow = 1
Window1.ScrollColumn = 1
'Set side by side
'Windows.CompareSideBySideWith Window2.Caption
CallByName Windows, "CompareSideBySideWith", VbMethod, Window2.Caption
'Windows.Arrange ArrangeStyle:=xlVertical
CallByName Windows, "Arrange", VbMethod, -4166 '(xlVertical)
'CallByName Windows, "Arrange", VbMethod, -4128 '(xlHorizontal)
'Open edit form
frmSyncScroll.Show vbModeless
Else
MsgBox "Only supported in Excel 2003 onwards.", vbExclamation
End If
End Sub
Public Function Min(Value1 As Integer, Value2 As Integer) As Integer
'Return the smallest of two numbers
If Value1 < Value2 Then
Min = Value1
Else
Min = Value2
End If
End Function
I have a 2003 macro which I inherited from someone else. In theory I believe it should run in 2007.
But when I run it I get the following error message.
Run-time error '445'
Object doesn't support this action
Here's the macro.
Can anyone help me to get it working please.
Thanks in advance
Dave
Option Explicit
Public Enum ExcelVersion
Excel2000
Excel2002
Excel2003
Excel2007
Excel2010
Unknown
End Enum
Function CheckExcelVersion() As ExcelVersion
'Check the Excel Version
Select Case Application.Version
Case "9.0"
CheckExcelVersion = Excel2000
Case "10.0"
CheckExcelVersion = Excel2002
Case "11.0"
CheckExcelVersion = Excel2003
Case "12.0"
CheckExcelVersion = Excel2007
Case "14.0"
CheckExcelVersion = Excel2010
Case Else
CheckExcelVersion = Unknown
End Select
End Function
Public Sub Run_Spreadsheet_Compare(Optional Session As String = "")
Dim fMain As New frmMain
fMain.OpenSession = Session
fMain.Show vbModal
'frmMain.Show vbModal
End Sub
Sub Run_SyncScroll()
Dim ApplicationVersion As ExcelVersion
ApplicationVersion = CheckExcelVersion()
'Feature added in Excel 2003
If ApplicationVersion >= Excel2003 Then
Dim Window1 As Window
Dim Window2 As Window
If Windows.Count < 2 Then
MsgBox "Need two Windows open to synchronise scrolling", vbExclamation
Exit Sub
End If
'Disable side by side
'Windows.BreakSideBySide
CallByName Windows, "BreakSideBySide", VbMethod
'Set the two windows to make side by side
Set Window1 = ActiveWindow
If Windows(1).Caption = Window1.Caption Then
Set Window2 = Windows(2)
Else
Set Window2 = Windows(1)
End If
'Normalise 2nd Window
Window2.Zoom = Window1.Zoom
Window2.Activate
Window2.ScrollRow = 1
Window2.ScrollColumn = 1
'Normalise 1st window
Window1.Activate
Window1.ScrollRow = 1
Window1.ScrollColumn = 1
'Set side by side
'Windows.CompareSideBySideWith Window2.Caption
CallByName Windows, "CompareSideBySideWith", VbMethod, Window2.Caption
'Windows.Arrange ArrangeStyle:=xlVertical
CallByName Windows, "Arrange", VbMethod, -4166 '(xlVertical)
'CallByName Windows, "Arrange", VbMethod, -4128 '(xlHorizontal)
'Open edit form
frmSyncScroll.Show vbModeless
Else
MsgBox "Only supported in Excel 2003 onwards.", vbExclamation
End If
End Sub
Public Function Min(Value1 As Integer, Value2 As Integer) As Integer
'Return the smallest of two numbers
If Value1 < Value2 Then
Min = Value1
Else
Min = Value2
End If
End Function