Devo utilzzare la funzione trova in due versioni differenti di office, il file può essere aperto da macchine con versioni differenti ma la macro deve funzionare.
Il problema è che il compilatore non ha ancora istanziato l'oggetto Application e quindi non lo trova e da errore nell'istruzione #if
Public Const EXCEL_2000 As Integer = 9
Public Const EXCEL_2002 As Integer = 10
Public Const EXCEL_2003 As Integer = 11
Public Const EXCEL_2007 As Integer = 12
Public Const EXCEL_2010 As Integer = 14
Function GetVersion() As Long
' returns application version
GetVersion = Val(Application.Version)
End Function
Sub trova()
Dim cerca As String
cerca = Range("ricerca").Value
' errore qui NON TROVA L'OGGETTO APPLICATION!!
#If Application.Version = 9 Then
'v2000:
'versione office 2000
On Error GoTo ExitTrova
Cells.Find(What:=cerca, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
#Else
'versione office superiore
Cells.Find(What:=cerca, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Exit Sub
#End If
ExitTrova:
End Sub
Qualcuno sa darmi una soluzione? grazie in anticipo
l'essenziale è invisibile agli occhi