Unable to open file

ryan8200

Active Member
Joined
Aug 21, 2011
Messages
357
I'm not able to open file with filename in Chinese character. It hit runtime error 1004 with following messages:

Sorry, we couldn't find C:\Users\My\Downloads\Data\?????.csv. Is it possible, it was moved, renamed or deleted". I have Chinese font been installed in both Window and Excel. What is the possible root cause for this problem ?

Here is the code I'm using:
VBA Code:
[/
Path = "C:\Users\My\Downloads\Data\"
Filename = Dir(Path & "*.csv")

  Do While Filename <> ""
  Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
     For Each Sheet In ActiveWorkbook.Sheets
     Sheet.Copy After:=ThisWorkbook.Sheets(1)
  Next Sheet
     Workbooks(Filename).Close
     Filename = Dir()
  Loop
CODE]
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Can you upload the file and provide a link to it?
 
Upvote 0
I think due to the VBA environment does not support Unicode. Try this

VBA Code:
Sub Test()

Dim wb As Workbook
Dim FSO As Object, Folder As Object, File As Object

Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder("C:\Users\My\Downloads\Data")

For Each File In Folder.Files
    Set wb = Workbooks.Open(Filename:=File, UpdateLinks:=False, ReadOnly:=True, IgnoreReadOnlyRecommended:=True)
    For Each Sheet In wb.Sheets
        Sheet.Copy After:=ThisWorkbook.Sheets(1)
    Next
    wb.Close False
Next

End Sub
 
Upvote 0
I think due to the VBA environment does not support Unicode. Try this

VBA Code:
Sub Test()

Dim wb As Workbook
Dim FSO As Object, Folder As Object, File As Object

Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder("C:\Users\My\Downloads\Data")

For Each File In Folder.Files
    Set wb = Workbooks.Open(Filename:=File, UpdateLinks:=False, ReadOnly:=True, IgnoreReadOnlyRecommended:=True)
    For Each Sheet In wb.Sheets
        Sheet.Copy After:=ThisWorkbook.Sheets(1)
    Next
    wb.Close False
Next

End Sub
Hi Zot, thanks. It works. The above code will read all files within the specified folder regardless of file type ? The solution is to create File System Object to handle unicode filename ?
 
Upvote 0
Hi Zot, thanks. It works. The above code will read all files within the specified folder regardless of file type ? The solution is to create File System Object to handle unicode filename ?
Yess, all files in folder. I guess you can just use wildcards to filter that out. Using the FSO you are going through Windows environment which able to handle unicode.

Ohh.. I should have add Application.ScreenUpdating = False to prevent flashing and make it run faster ?
 
Upvote 0

Forum statistics

Threads
1,214,840
Messages
6,121,895
Members
449,058
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top