Problem With Macro (csv file)

floni

New Member
Joined
Jan 17, 2018
Messages
4
Hi,

below my Macro:

Sub AllFiles()
Dim folderPath As String
Dim filename As String
Dim wb As Workbook

folderPath = "C:\Users\Dom\Desktop\Bob"

If Right(folderPath, 1) <> "" Then folderPath = folderPath + ""

filename = Dir(folderPath & "*.csv")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath, Local:=True & filename)



Call ChangeFile


filename = Dir
Loop
Application.ScreenUpdating = True
End Sub

I need to open CSV file with data like Excel, so I wrote Local:=True, but then i have error:"run time error 1004 method open of object workbooks failed"

Any help is greatly appreciated!!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try this.
Code:
Set wb = Workbooks.Open(folderPath &"\" & filename)
 
Upvote 0
Hi, Now I don't have error but when I open the file the data format is like csv. The second macro ChangeFile needs xls/xlsx data format.
 
Upvote 0
What do you mean by 'data format ... like csv'?
 
Upvote 0
For example: all data are in A1 like aa;aa and should in column A1 aa and B1 aa. When I open the CSV file and use that: [FONT=&quot]Workbooks.Open Filename:=[/FONT]"C:\Users\Dom\Desktop\Bob"[FONT=&quot], Local:=True - then is ok. [/FONT]
 
Upvote 0
Try this then.
Code:
Set wb = Workbooks.Open(FileName:=folderPath &"\" & filename, Local:=True)
 
Upvote 0

Forum statistics

Threads
1,215,090
Messages
6,123,061
Members
449,091
Latest member
ikke

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