I have a script for searching an Excel sheet for an input value, which, if found, returns the file number associated with it, using
.
This code works well from Excel, but I found that when trying to use it from Outlook, I run into a compile error:
Method or Data Member Not Found
with reference to the .offset (item? I'm not sure what it is called)... Of course, it doesn't matter if it is .offset, or anything else after rngFound, because none of those are apparently used in Outlook vba, without some other qualification that I am unaware of.
Can someone help point me in the right direction? My interwebs search has been fruitless - not a lot of people trying to search Excel from Outlook, and those that do, aren't doing the more extensive type of search I'm doing. I did encounter some references to needing to fully qualify everything, but it seems to me that is accomplished prior to the error.
Here's my full script:
VBA Code:
sfilenum = rngFound.Offset(0, 0).EntireRow.Range("A1").Value
This code works well from Excel, but I found that when trying to use it from Outlook, I run into a compile error:
Method or Data Member Not Found
with reference to the .offset (item? I'm not sure what it is called)... Of course, it doesn't matter if it is .offset, or anything else after rngFound, because none of those are apparently used in Outlook vba, without some other qualification that I am unaware of.
Can someone help point me in the right direction? My interwebs search has been fruitless - not a lot of people trying to search Excel from Outlook, and those that do, aren't doing the more extensive type of search I'm doing. I did encounter some references to needing to fully qualify everything, but it seems to me that is accomplished prior to the error.
Here's my full script:
VBA Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim strSearchString As String
Dim sfilenum As String
strSearchString = Trim(TextBox1.Value)
If InStr(strSearchString, " ") Then
strSearchString = Replace(strSearchString, " ", "")
End If
If InStr(strSearchString, "-") Then
strSearchString = Replace(strSearchString, "-", "")
End If
Dim xlapp As Excel.Application
Dim xlwb As Excel.Workbook
Dim xlws As Excel.Worksheet
Set xlapp = GetObject(, "Excel.Application")
Set xlwb = xlapp.Workbooks("GBOOK.xlsx")
If xlwb Is Nothing Then
xlapp.Workbooks.Open ("C:\ONEDRIVE\GBOOK.XLSX")
Set xlwb = xlapp.Workbooks("GBOOK.xlsx")
Else
End If
Set xlws = xlwb.Sheets("MASTER")
If xlwb Is Nothing Then
MsgBox "Required file is not available"
End If
Dim rngFound As Range
Set rngFound = xlws.Cells.Find(What:=strSearchString, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Value Not Found.", vbOKOnly, "GBook"
Exit Sub
Else
sfilenum = rngFound.Offset(0, 0).EntireRow.Range("A1").Value 'ERRORS HERE: METHOD OR DATA MEMBER NOT FOUND
End If
If sfilenum = "FILENUM" Then Exit Sub
'10/26/19 Adding multiple use clipboard function
With New MSForms.DataObject
.SetText sfilenum
.PutInClipboard
End With
' Call MsgBoxTimeout(0, "File# " & sfilenum & " copied to clipboard.", "GBook", vbInformation, 0, 3000)
TextBox1.Value = "SEARCH BOX"
Set rngFound = Nothing
End Sub