![]() |
pass workbook on to function?
I have a function which looks an item up in another workbook... the
work book is created as: set lookup = workbooks.open.... later I try to use that in a function, as: Function FindItem(item As String) As Boolean ' look for item in other document j = iIndexStart While (item < lookup.Sheets(1).Cells(j, 2)) And (lookup.Sheets(1).Cells(j, 2) < "") j = j + 1 Result: obejct not found Trying passing it as a parameter does not compile Function FindItem(item As String, loc as workbook) As Boolean ' look for item in other document j = iIndexStart While (item < loc.Sheets(1).Cells(j, 2)) And (loc.Sheets(1).Cells(j, 2) < "") j = j + 1 what do I do wrong? |
pass workbook on to function?
You can use a string to pass a workbook name:
Sub Macro1() Dim s As String s = "Book2" Call bringup(s) End Sub Sub bringup(s As String) Dim w As Workbook Workbooks(s).Activate End Sub There are similar ways to convert string into worksheets, strings in ranges, etc. -- Gary's Student "Sonnich" wrote: I have a function which looks an item up in another workbook... the work book is created as: set lookup = workbooks.open.... later I try to use that in a function, as: Function FindItem(item As String) As Boolean ' look for item in other document j = iIndexStart While (item < lookup.Sheets(1).Cells(j, 2)) And (lookup.Sheets(1).Cells(j, 2) < "") j = j + 1 Result: obejct not found Trying passing it as a parameter does not compile Function FindItem(item As String, loc as workbook) As Boolean ' look for item in other document j = iIndexStart While (item < loc.Sheets(1).Cells(j, 2)) And (loc.Sheets(1).Cells(j, 2) < "") j = j + 1 what do I do wrong? |
All times are GMT +1. The time now is 05:16 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com