James Snyder
Well-known Member
- Joined
- Jan 11, 2013
- Messages
- 618
I am working with multiple workbooks from a master workbook and need to pass a workbook object and worksheet object as ByRef parameters. I am successful in other functions, but am not figuring out how to do it into a function that is generic.
I am using Excel 2010, workbooks are made in 2003 and saved to 2010 before being referenced, and the passed references get used in multiple functions.
The declarations are in Main():
The function call that isn't working:
The function:
</snip>
I am using Excel 2010, workbooks are made in 2003 and saved to 2010 before being referenced, and the passed references get used in multiple functions.
The declarations are in Main():
Code:
Dim obstWkBook As Workbook
Dim obstWkSheet As Worksheet
Dim [COLOR=#008000]workOWkBook[/COLOR] As Workbook
Dim [COLOR=#008000]workOWkSheet[/COLOR] As Worksheet
Dim ftpWkBook As Workbook
Dim ftpWkSheet As Worksheet
Dim arrDupes() As String
Static sendDate As String
Dim funcReturn As String
Dim failReturn As String
Dim errString As String
The function call that isn't working:
Code:
funcReturn = PSIDDupeCheck([COLOR=#008000]workOWkBook[/COLOR], [COLOR=#008000]workOWkSheet[/COLOR], arrDupes, sendDate)
If funcReturn <> "Success" Then
errString = "DupeCheck fail: Error while checking for PSID duplicates"
failReturn = ProblemReport(errString, sendDate)
Err.Clear
GoTo ExitPoint
End If
The function:
Code:
Private Function PSIDDupeCheck([COLOR=#008000]ByRef wkBook As Workbook[/COLOR], _
[COLOR=#008000]ByRef wkSheet As Worksheet[/COLOR], _
ByRef dupeArray() As String, _
ByRef sendDate As String) As String
Dim rowMax As Long
Dim dupeRow As Long
Dim i As Long
Dim failReturn As String
Dim errString As String
[COLOR=#008000]wkBook[/COLOR].Open [COLOR=#ff0000]<=== Fails here with Run-time error '424' Object Required[/COLOR]
Workbooks.Open [COLOR=#008000]wkBook[/COLOR] [COLOR=#ff0000]<=== or fails here with Run-time error '424' Object Required[/COLOR]
If Not [COLOR=#008000]wkBook[/COLOR] Is Nothing Then
'<<snip>>
Else
errString = "WorkOrders: Failed to open workbook get dupes"
failReturn = ProblemReport(errString, sendDate)
Err.Clear
PSIDDupeCheck = errString
End If
wkSheet = Nothing
wkBook = Nothing
End Function