473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to fix Run-time Error 52 for Microsoft Excel 2003?

The following works well in local share network drive. However, when the file is transfer over to the open network (view from internet), the following excel file will show error: Run-time error: 52. Bad file name or number.

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
  1. ' VBA code for one of the button created for user to click
  2.  
  3. Private Sub UserForm_Initialize()
  4. fpath = "http://teamsite.UATnet.COM.US/sites/DHH/Shared Documents/ESMS - Enquiry" & "/"
  5.  
  6. KAS_file = "KAS EBook.xlsx"
  7. LC_file = "LC EBook.xlsx"
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDoc_Click()
  2. If Uref <> "" Or Uref <> Null Or Lref <> "" Or Lref <> Null Then
  3.     LC_Result = SearchnListFile(LC_file, "A", "B", "C", "D", "E", "F", "G", "H", 1)
  4.     KAS_Result = SearchnListFile(KAS_file, "A", "B", "C", "D", "E", "F", "G", "H", 2)
  5.     tbSearch.Text = ""
  6.     tbSearch.SetFocus
  7.     ref = ""
  8.     If ThisWorkbook.Worksheets("SearchResult").Range("D3") = "" Then
  9.         msgResponse = MsgBox("The data you're searching cannot be found under Legal Document Team.", , "Result")
  10.     Else
  11.         Unload SearchForm
  12.         Unload ESBook
  13.         DisplayArrange
  14.     End If
  15.  
  16. ElseIf Uref = "" Or Lref = "" Then
  17.     msgResponse = MsgBox("Sorry, you did not enter any data! Please enter a valid data.", , "Error")
  18. End If
  19. End Sub
' If the user click on the selected button, the following function will be executed.
Expand|Select|Wrap|Line Numbers
  1. Private Function SearchnListFile(file_name, letter1, letter2, letter3, letter4, _
  2.                                  letter5, letter6, letter7, letter8, clr)
  3. Dim file_path As String
  4. Dim NoOfRow As Long
  5. Dim temp As String
  6. file_path = fpath & file_name
  7.  
  8. If Dir(file_path) <> "" Then
  9.     Dim mth As Integer
  10.     Dim box As Long
  11.     Dim count As Integer
  12.     count = 0
  13.     NoOfRow = 0
  14. End If
  15.  
  16. If clr = 1 Then
  17.     ThisWorkbook.Worksheets("SearchResult").Range("A3:H6000").Clear
  18.     Workbooks.Open Filename:=file_path, ReadOnly:=True
  19.     Workbooks(file_name).Activate
  20.     For mth = 1 To 3
  21.         Worksheets(mth).Activate
  22.         For box = 3 To 6000
  23.             If ActiveSheet.Range("C" & box).Value = Uref Or _
  24.             ActiveSheet.Range("D" & box).Value = Uref Or _
  25.             ActiveSheet.Range("D" & box).Value = Lref Or _
  26.             ActiveSheet.Range("E" & box).Value = Uref Or _
  27.             ActiveSheet.Range("E" & box).Value = Lref Or _
  28.             ActiveSheet.Range("G" & box).Value = Uref Or _
  29.             ActiveSheet.Range("G" & box).Value = Lref Or _
  30.             ActiveSheet.Range("H" & box).Value = Uref Or _
  31.             ActiveSheet.Range("H" & box).Value = Lref Then
  32.                 count = count + 1
  33.                 ActiveSheet.Range("B" & box).Copy _
  34.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  35.                 Range(letter2 & count + 2)
  36.                 ActiveSheet.Range("C" & box).Copy _
  37.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  38.                 Range(letter3 & count + 2)
  39.                 ActiveSheet.Range("D" & box).Copy _
  40.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  41.                 Range(letter4 & count + 2)
  42.                 ActiveSheet.Range("E" & box).Copy _
  43.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  44.                 Range(letter5 & count + 2)
  45.                 ActiveSheet.Range("F" & box).Copy _
  46.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  47.                 Range(letter6 & count + 2)
  48.                 ActiveSheet.Range("G" & box).Copy _
  49.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  50.                 Range(letter7 & count + 2)
  51.                 ActiveSheet.Range("H" & box).Copy _
  52.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  53.                 Range(letter8 & count + 2)
  54.             ElseIf ActiveSheet.Range("B" & box).Value = Empty And _
  55.                    ActiveSheet.Range("C" & box).Value = Empty And _
  56.                    ActiveSheet.Range("D" & box).Value = Empty And _
  57.                    ActiveSheet.Range("E" & box).Value = Empty And _
  58.                    ActiveSheet.Range("F" & box).Value = Empty And _
  59.                    ActiveSheet.Range("G" & box).Value = Empty And _
  60.                    ActiveSheet.Range("H" & box).Value = Empty Then Exit For
  61.         Exit For
  62.             End If
  63.     Next
  64. Next
  65.     Workbooks(file_name).Close SaveChanges:=False
  66.  
  67. ElseIf clr = 2 Then
  68.     ThisWorkbook.Worksheets("SearchResult").Activate
  69.     For box = 3 To 6000
  70.         If ActiveSheet.Range("D" & box).Value = Uref Or _
  71.         ActiveSheet.Range("D" & box).Value = Lref Then
  72.             NoOfRow = NoOfRow + 1
  73.         End If
  74.     Next
  75.     Workbooks.Open Filename:=file_path, ReadOnly:=True
  76.     Workbooks(file_name).Activate
  77.     For mth = 1 To 3
  78.         Worksheets(mth).Activate
  79.         For box = 3 To 6000
  80.             If ActiveSheet.Range("C" & box).Value = Uref Or _
  81.             ActiveSheet.Range("D" & box).Value = Uref Or _
  82.             ActiveSheet.Range("D" & box).Value = Lref Or _
  83.             ActiveSheet.Range("E" & box).Value = Uref Or _
  84.             ActiveSheet.Range("E" & box).Value = Lref Or _
  85.             ActiveSheet.Range("G" & box).Value = Uref Or _
  86.             ActiveSheet.Range("G" & box).Value = Lref Or _
  87.             ActiveSheet.Range("H" & box).Value = Uref Or _
  88.             ActiveSheet.Range("H" & box).Value = Lref Then
  89.                 count = count + 1
  90.                 ActiveSheet.Range("B" & box).Copy _
  91.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  92.                 Range(letter2 & count + NoOfRow + 2)
  93.                 ActiveSheet.Range("C" & box).Copy _
  94.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  95.                 Range(letter3 & count + NoOfRow + 2)
  96.                 ActiveSheet.Range("D" & box).Copy _
  97.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  98.                 Range(letter4 & count + NoOfRow + 2)
  99.                 ActiveSheet.Range("E" & box).Copy _
  100.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  101.                 Range(letter5 & count + NoOfRow + 2)
  102.                 ActiveSheet.Range("F" & box).Copy _
  103.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  104.                 Range(letter6 & count + NoOfRow + 2)
  105.                 ActiveSheet.Range("G" & box).Copy _
  106.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  107.                 Range(letter7 & count + NoOfRow + 2)
  108.                 ActiveSheet.Range("H" & box).Copy _
  109.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  110.                 Range(letter8 & count + NoOfRow + 2)
  111.             ElseIf ActiveSheet.Range("B" & box).Value = Empty And _
  112.                    ActiveSheet.Range("C" & box).Value = Empty And _
  113.                    ActiveSheet.Range("D" & box).Value = Empty And _
  114.                    ActiveSheet.Range("E" & box).Value = Empty And _
  115.                    ActiveSheet.Range("F" & box).Value = Empty And _
  116.                    ActiveSheet.Range("G" & box).Value = Empty And _
  117.                    ActiveSheet.Range("H" & box).Value = Empty Then Exit For
  118.             End If
  119.     Next
  120. Next
  121.  
  122. Workbooks(file_name).Close SaveChanges:=False
  123.  
  124. ElseIf clr = 3 Then
  125.     ThisWorkbook.Worksheets("SearchResult").Activate
  126.     For box = 3 To 6000
  127.         If ActiveSheet.Range("D" & box).Value = Uref Or _
  128.         ActiveSheet.Range("D" & box).Value = Lref Then
  129.             NoOfRow = NoOfRow + 1
  130.         End If
  131.     Next
  132.  
  133.     Workbooks.Open Filename:=file_path, ReadOnly:=True
  134.     Workbooks(file_name).Activate
  135.     For mth = 4 To 4
  136.         Worksheets(mth).Activate
  137.         For box = 3 To 10000
  138.             If ActiveSheet.Range("D" & box).Value = Uref Or _
  139.             ActiveSheet.Range("D" & box).Value = Lref Then
  140.                 count = count + 1
  141.                 ActiveSheet.Range("B" & box).Copy _
  142.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  143.                 Range(letter2 & count + NoOfRow + 2)
  144.                 ActiveSheet.Range("C" & box).Copy _
  145.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  146.                 Range(letter3 & count + NoOfRow + 2)
  147.                 ActiveSheet.Range("D" & box).Copy _
  148.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  149.                 Range(letter4 & count + NoOfRow + 2)
  150.                 ActiveSheet.Range("E" & box).Copy _
  151.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  152.                 Range(letter5 & count + NoOfRow + 2)
  153.                 ActiveSheet.Range("F" & box).Copy _
  154.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  155.                 Range(letter6 & count + NoOfRow + 2)
  156.                 ActiveSheet.Range("G" & box).Copy _
  157.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  158.                 Range(letter7 & count + NoOfRow + 2)
  159.                 ActiveSheet.Range("H" & box).Copy _
  160.                 Destination:=ThisWorkbook.Worksheets("SearchResult"). _
  161.                 Range(letter8 & count + NoOfRow + 2)
  162.             ElseIf ActiveSheet.Range("B" & box).Value = Empty And _
  163.                    ActiveSheet.Range("C" & box).Value = Empty And _
  164.                    ActiveSheet.Range("D" & box).Value = Empty And _
  165.                    ActiveSheet.Range("E" & box).Value = Empty And _
  166.                    ActiveSheet.Range("F" & box).Value = Empty And _
  167.                    ActiveSheet.Range("G" & box).Value = Empty And _
  168.                    ActiveSheet.Range("H" & box).Value = Empty Then Exit For
  169.             End If
  170.     Next
  171. Next
  172.  
  173. Workbooks(file_name).Close SaveChanges:=False
  174. Else
  175.     msgResponse = MsgBox("File cannot be found in path: " & file_path, , "Error")
  176. End If
  177.  
  178.  
  179. End Function
Feb 29 '16 #1
1 3276
zmbd
5,501 Expert Mod 4TB
First code block Userform_Intialize:
Hopefully a typo; however, no end sub
In anycase, from what you have shown, the value of line-4 is local in scope to this procedure; thus at the end, is lost to the remaining procedures. This holds true for Lines 6 and 7

Second code block CmdDoc_Click
Lines 3 and 4 refer to values that you have not defined in the local scope, from what you've shown...

Third code block SearchListFile
Because the values in the second block are not defined then the values that Line-6 refers to values not set within the local scope - once again, from what information you have provided us...

Line-8, to the best of my understanding, DIR() does not work on HTML, in fact, I donot believe that the DIR() even supports UNC path conventions.


You might try using the external data method
Support.office: Connect external data to your workbook -- From Web Make sure you name the connection

The nice thing here is that you can open a new workbook,
Excel2013>Ribbon>View>Macros>MacrosDropDown>Record Macro

Then use the above method to generate your base code to link to the workbook. Make sure that you include code to remove the link once its use is over or you may have some irate users as each time the code runs it will attempt to add the link and as it already exists you will either create a bandwidth overload or the name may already be in the workbooks links creating an error.
May 7 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Igor | last post by:
Hi everyone! I have a program written on C# that works with Microsoft Excel application. I built it to work with Excel 2000. With runtime objects I created assemblies to connect to Excel....
1
by: Tim Groulx | last post by:
Hello All, I am getting the following error when attemping to open a table in SQL2kSP3a. ________________________________________ SQL Server Enterprise Manager Database Server: Microsoft SQL...
1
by: cybertof | last post by:
Hello, Is there a way to connect (through automation) a c# application to a running Excel 2003 instance on a specific workbook ? In the past, i used to use GetObject(...) function in VB6. ...
0
by: ann | last post by:
Hi, I am trying to add an ActiveX control on my ASP.NET web form (the language for code behind is C#). I have some client-side vbscript to handle events from the html input buttons. In the...
1
by: keithb | last post by:
What causes this intermittent runtime error? Microsoft Jscript Runtime Error: 'ct100_TreeView1_Data is undefined. When the error occurs, the following section of code is highlighted: on...
0
by: jason_cuteboy | last post by:
Hi all, Completely new to Vb.net and trying to create a simple VB Office Excel application/spreadsheet. When I built the project, and excel opens up an error comes up.... Customization assembly...
10
by: Patrick Schmid [MVP] | last post by:
I have no idea what is going on... I took an add-in for Office 2007 that I started in VS 2003, and imported the whole thing into VS 2005. Then I added some custom .Net components from Developer...
0
by: Mark123 | last post by:
Every time people using our 97 Runtime App try to export (OutputTo) a previewed report to Excel or Word 2003 it gives a "Microsoft Access has encountered an error" and then proceeds to crash and...
2
by: Nicholas Dreyer | last post by:
The following error Run-time exception thrown : System.Runtime.InteropServices.COMException - Error loading type library/DLL. happens while running the code listed at the bottom of this...
8
by: Fendi Baba | last post by:
I created an ASP.net page which opens excel. The data opens up correctly in MS office Excel 2007 but when we use a mahcine with MS Office 2003 we encountered a message, "Cannot read output file" Is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.