Need assistance with following code...
Word macro, loads excel then performs a find there...
But i get an error 91 on the find command... any pointers?
Sub GetEAN()
Dim res As String
Dim cur As String
Dim scount As Integer
Dim found As Integer
Dim i As Integer
Dim lRange As String
Dim t As Long
Dim oApp As Excel.Application
Dim wb As Excel.Workbook
Dim wRange As Excel.Range
Dim vEAN As String
Dim vREF As String
' default value for EAN if something is highlighted
cur = Selection.Text
res = InputBox("Enter REF code to search for...", "Get REF", cur)
If res = "" Then
Exit Sub
End If
If Tasks.Exists("Microsoft Excel"
= True Then
Set oApp = GetObject(, "Excel.Application"
Else
Set oApp = CreateObject("Excel.Application"
End If
oApp.Visible = True
If oApp.Workbooks.Count = 0 Then
' load workbook
Set wb = oApp.Workbooks.Open(FileName:="c:\Data\Pricelists\TARIFHOME2003.xls"
Else
Set wb = oApp.ActiveWorkbook
End If
If wb Is Nothing Then
MsgBox "Workbook is nothing"
Exit Sub
End If
found = 0
For i = 1 To oApp.Sheets.Count
scount = 1
Set wRange = wb.Worksheets(i).Cells
t = wRange.Find(What:=res, _
Lookat:=xlWhole, _
SearchDirection:=xlByRows, _
SearchOrder:=xlNext).Activate
scount = ActiveCell.Row
If scount <> 1 Then
found = i
Exit For
End If
Next i
Word macro, loads excel then performs a find there...
But i get an error 91 on the find command... any pointers?
Sub GetEAN()
Dim res As String
Dim cur As String
Dim scount As Integer
Dim found As Integer
Dim i As Integer
Dim lRange As String
Dim t As Long
Dim oApp As Excel.Application
Dim wb As Excel.Workbook
Dim wRange As Excel.Range
Dim vEAN As String
Dim vREF As String
' default value for EAN if something is highlighted
cur = Selection.Text
res = InputBox("Enter REF code to search for...", "Get REF", cur)
If res = "" Then
Exit Sub
End If
If Tasks.Exists("Microsoft Excel"
Set oApp = GetObject(, "Excel.Application"
Else
Set oApp = CreateObject("Excel.Application"
End If
oApp.Visible = True
If oApp.Workbooks.Count = 0 Then
' load workbook
Set wb = oApp.Workbooks.Open(FileName:="c:\Data\Pricelists\TARIFHOME2003.xls"
Else
Set wb = oApp.ActiveWorkbook
End If
If wb Is Nothing Then
MsgBox "Workbook is nothing"
Exit Sub
End If
found = 0
For i = 1 To oApp.Sheets.Count
scount = 1
Set wRange = wb.Worksheets(i).Cells
t = wRange.Find(What:=res, _
Lookat:=xlWhole, _
SearchDirection:=xlByRows, _
SearchOrder:=xlNext).Activate
scount = ActiveCell.Row
If scount <> 1 Then
found = i
Exit For
End If
Next i