I have change the fpath to the following instead of fpath = ThisWorkbook.path & "\" but still having the same error.
Can anyone help? which code should I amend?
---------------------------------------------------------
Expand|Select|Wrap|Line Numbers
- ' VBA code for one of the button created for user to click
- Private Sub UserForm_Initialize()
- fpath = "http://teamsite.UATnet.COM.US/sites/DHH/Shared Documents/ESMS - Enquiry" & "/"
- KAS_file = "KAS EBook.xlsx"
- LC_file = "LC EBook.xlsx"
Expand|Select|Wrap|Line Numbers
- Private Sub cmdDoc_Click()
- If Uref <> "" Or Uref <> Null Or Lref <> "" Or Lref <> Null Then
- LC_Result = SearchnListFile(LC_file, "A", "B", "C", "D", "E", "F", "G", "H", 1)
- KAS_Result = SearchnListFile(KAS_file, "A", "B", "C", "D", "E", "F", "G", "H", 2)
- tbSearch.Text = ""
- tbSearch.SetFocus
- ref = ""
- If ThisWorkbook.Worksheets("SearchResult").Range("D3") = "" Then
- msgResponse = MsgBox("The data you're searching cannot be found under Legal Document Team.", , "Result")
- Else
- Unload SearchForm
- Unload ESBook
- DisplayArrange
- End If
- ElseIf Uref = "" Or Lref = "" Then
- msgResponse = MsgBox("Sorry, you did not enter any data! Please enter a valid data.", , "Error")
- End If
- End Sub
Expand|Select|Wrap|Line Numbers
- Private Function SearchnListFile(file_name, letter1, letter2, letter3, letter4, _
- letter5, letter6, letter7, letter8, clr)
- Dim file_path As String
- Dim NoOfRow As Long
- Dim temp As String
- file_path = fpath & file_name
- If Dir(file_path) <> "" Then
- Dim mth As Integer
- Dim box As Long
- Dim count As Integer
- count = 0
- NoOfRow = 0
- End If
- If clr = 1 Then
- ThisWorkbook.Worksheets("SearchResult").Range("A3:H6000").Clear
- Workbooks.Open Filename:=file_path, ReadOnly:=True
- Workbooks(file_name).Activate
- For mth = 1 To 3
- Worksheets(mth).Activate
- For box = 3 To 6000
- If ActiveSheet.Range("C" & box).Value = Uref Or _
- ActiveSheet.Range("D" & box).Value = Uref Or _
- ActiveSheet.Range("D" & box).Value = Lref Or _
- ActiveSheet.Range("E" & box).Value = Uref Or _
- ActiveSheet.Range("E" & box).Value = Lref Or _
- ActiveSheet.Range("G" & box).Value = Uref Or _
- ActiveSheet.Range("G" & box).Value = Lref Or _
- ActiveSheet.Range("H" & box).Value = Uref Or _
- ActiveSheet.Range("H" & box).Value = Lref Then
- count = count + 1
- ActiveSheet.Range("B" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter2 & count + 2)
- ActiveSheet.Range("C" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter3 & count + 2)
- ActiveSheet.Range("D" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter4 & count + 2)
- ActiveSheet.Range("E" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter5 & count + 2)
- ActiveSheet.Range("F" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter6 & count + 2)
- ActiveSheet.Range("G" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter7 & count + 2)
- ActiveSheet.Range("H" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter8 & count + 2)
- ElseIf ActiveSheet.Range("B" & box).Value = Empty And _
- ActiveSheet.Range("C" & box).Value = Empty And _
- ActiveSheet.Range("D" & box).Value = Empty And _
- ActiveSheet.Range("E" & box).Value = Empty And _
- ActiveSheet.Range("F" & box).Value = Empty And _
- ActiveSheet.Range("G" & box).Value = Empty And _
- ActiveSheet.Range("H" & box).Value = Empty Then Exit For
- Exit For
- End If
- Next
- Next
- Workbooks(file_name).Close SaveChanges:=False
- ElseIf clr = 2 Then
- ThisWorkbook.Worksheets("SearchResult").Activate
- For box = 3 To 6000
- If ActiveSheet.Range("D" & box).Value = Uref Or _
- ActiveSheet.Range("D" & box).Value = Lref Then
- NoOfRow = NoOfRow + 1
- End If
- Next
- Workbooks.Open Filename:=file_path, ReadOnly:=True
- Workbooks(file_name).Activate
- For mth = 1 To 3
- Worksheets(mth).Activate
- For box = 3 To 6000
- If ActiveSheet.Range("C" & box).Value = Uref Or _
- ActiveSheet.Range("D" & box).Value = Uref Or _
- ActiveSheet.Range("D" & box).Value = Lref Or _
- ActiveSheet.Range("E" & box).Value = Uref Or _
- ActiveSheet.Range("E" & box).Value = Lref Or _
- ActiveSheet.Range("G" & box).Value = Uref Or _
- ActiveSheet.Range("G" & box).Value = Lref Or _
- ActiveSheet.Range("H" & box).Value = Uref Or _
- ActiveSheet.Range("H" & box).Value = Lref Then
- count = count + 1
- ActiveSheet.Range("B" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter2 & count + NoOfRow + 2)
- ActiveSheet.Range("C" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter3 & count + NoOfRow + 2)
- ActiveSheet.Range("D" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter4 & count + NoOfRow + 2)
- ActiveSheet.Range("E" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter5 & count + NoOfRow + 2)
- ActiveSheet.Range("F" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter6 & count + NoOfRow + 2)
- ActiveSheet.Range("G" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter7 & count + NoOfRow + 2)
- ActiveSheet.Range("H" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter8 & count + NoOfRow + 2)
- ElseIf ActiveSheet.Range("B" & box).Value = Empty And _
- ActiveSheet.Range("C" & box).Value = Empty And _
- ActiveSheet.Range("D" & box).Value = Empty And _
- ActiveSheet.Range("E" & box).Value = Empty And _
- ActiveSheet.Range("F" & box).Value = Empty And _
- ActiveSheet.Range("G" & box).Value = Empty And _
- ActiveSheet.Range("H" & box).Value = Empty Then Exit For
- End If
- Next
- Next
- Workbooks(file_name).Close SaveChanges:=False
- ElseIf clr = 3 Then
- ThisWorkbook.Worksheets("SearchResult").Activate
- For box = 3 To 6000
- If ActiveSheet.Range("D" & box).Value = Uref Or _
- ActiveSheet.Range("D" & box).Value = Lref Then
- NoOfRow = NoOfRow + 1
- End If
- Next
- Workbooks.Open Filename:=file_path, ReadOnly:=True
- Workbooks(file_name).Activate
- For mth = 4 To 4
- Worksheets(mth).Activate
- For box = 3 To 10000
- If ActiveSheet.Range("D" & box).Value = Uref Or _
- ActiveSheet.Range("D" & box).Value = Lref Then
- count = count + 1
- ActiveSheet.Range("B" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter2 & count + NoOfRow + 2)
- ActiveSheet.Range("C" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter3 & count + NoOfRow + 2)
- ActiveSheet.Range("D" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter4 & count + NoOfRow + 2)
- ActiveSheet.Range("E" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter5 & count + NoOfRow + 2)
- ActiveSheet.Range("F" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter6 & count + NoOfRow + 2)
- ActiveSheet.Range("G" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter7 & count + NoOfRow + 2)
- ActiveSheet.Range("H" & box).Copy _
- Destination:=ThisWorkbook.Worksheets("SearchResult"). _
- Range(letter8 & count + NoOfRow + 2)
- ElseIf ActiveSheet.Range("B" & box).Value = Empty And _
- ActiveSheet.Range("C" & box).Value = Empty And _
- ActiveSheet.Range("D" & box).Value = Empty And _
- ActiveSheet.Range("E" & box).Value = Empty And _
- ActiveSheet.Range("F" & box).Value = Empty And _
- ActiveSheet.Range("G" & box).Value = Empty And _
- ActiveSheet.Range("H" & box).Value = Empty Then Exit For
- End If
- Next
- Next
- Workbooks(file_name).Close SaveChanges:=False
- Else
- msgResponse = MsgBox("File cannot be found in path: " & file_path, , "Error")
- End If
- End Function