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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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