Error 52 in Excel VBA - add columns to csv & resave as xlsx

August 16, 2015 at 11:05:08
Specs: Windows 7
Hi all,

Total newbie at VBA here, so any help would be greatly appreciated.

Here is my code. I'm getting an error at "Filename = Dir(Pathname & "*.csv")" and can't figure out why. My aim is to insert some columns of data into the CSV, create a chart, and resave as XLSX. That's it! Thanks in advance.

Sub ProcessFiles()
Dim Filename, Pathname As String
Dim wb As Workbook

Pathname = ActiveWorkbook.Path & "C:\Users\Username\Desktop\csv\csv\"
Filename = Dir(Pathname & "*.csv")
Do While Filename <> ""
Set wb = Workbooks.Open(Pathname & Filename)
DoWork wb
wb.Close SaveChanges:=True
Filename = Dir(Pathname & ".xlsx")
End Sub

Sub DoWork(wb As Workbook)
With wb
End With
End Sub

message edited by jswalker

See More: Error 52 in Excel VBA - add columns to csv & resave as xlsx

Report •

August 16, 2015 at 18:54:37
I don't have access to Excel or VBA to test anything, but your construction of the Pathname variable doesn't look right to me.

Isn't ActiveWorkbook.Path going to return an entire path including the drive letter, etc.?

Then you appear to be concatenating another complete file path onto that. The variable won't care, but once you try to use that illegal path with the Dir instruction, it basically barfs all over itself. Barf is a technical term ;-)

Aren't you going to end up with something like this?


Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

message edited by DerbyDad03

Report •
Related Solutions

Ask Question