VBA Excel file to CSV, keeps CSV filename same as original workbook

前端 未结 3 1852
鱼传尺愫
鱼传尺愫 2021-01-27 15:36

I am trying to find a fast way to save my xlsx files as csv files with the same file-name as the xlsx file (just in csv forma

3条回答
  •  北海茫月
    2021-01-27 15:57

    Right now, you've got the file-name hard-coded in after "ActiveWorkbook.SaveAs" so it's saving everything with that hard-coded name.

    I think you'll want to use "ActiveWorkbook.Name" to get the name of the current file and concatenate it into the "Filename" variable that you have there (without the file extension) with the new extension. For example:

    "C:\Users\padd\Desktop\NEW CSV...ok!\" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1) & ".csv")
    

    This is a kind of a dirty way to do it, but it should serve your needs. Also, depending on which version of Excel you use, I think you might need to use "ThisWorkbook" instead of "ActiveWorkbook" but I'm not sure.

提交回复
热议问题