Share via

.xlsm to .csv vba code

Anonymous
2020-03-26T17:49:36+00:00

I need vba code to automatically copy a .xlsm file and save that copy as a .csv file with a new file name

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2020-03-27T17:47:46+00:00

    Hi,

    scenario:

    copy active sheet as  CSV file on desktop (name: tmp_XXXX.csv)

    try this code....

    Sub ActiveSheet_to_CSV()

     '## 27-03-2020 ##

    Dim ws As Worksheet

    Set ws = ActiveSheet

    Dim sFile As String

    sFile = Environ("USERPROFILE") & "\Desktop" & "tmp_" & WorksheetFunction.RandBetween(1111, 9999) & ".csv"

    ws.Copy

    Application.DisplayAlerts = False

    ActiveWorkbook.SaveAs sFile, FileFormat:=xlCSV, Local:=True

    ActiveWorkbook.Close False

    Application.DisplayAlerts = True

    End Sub

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2020-03-26T22:58:06+00:00

    Have tried Record Macro?

    Arguably, the result is often overkill and not the best way to do it.

    But it's a start.  And it might be sufficient for your purposes.

    0 comments No comments