Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VBA to covert sheet into *.csv with capital letter file extension

I have been working with the VBA code below and the code worked fine (creating a file with a .csv extension.

Today, my firm had an Office 365 update and for some reason the same code without edit, creates a file with a .CSV extension making it unable to be read by certain progams (it needs to be edited with the lowercase extension to be used further).

What do I need to know/alter in my settings to make my code run like prior?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Sub CSV_transfer()
    Dim header As Range
    Dim rngToSave As Range

Application.DisplayAlerts = False

    Windows("file.xlsm").Activate
    
    'Add a new sheet to become your csv and paste data
    Sheets.Add After:=ActiveSheet
    
    Set header = Sheets("sheet1").Range("AY3:AY6")
        header.Copy
    ActiveSheet.Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    Set rngToSave = Sheets("sheet1").Range("AX3:AX450")
        rngToSave.Copy
    ActiveSheet.Range("A5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
        
    'Move the sheet into it's own instance
    ActiveSheet.Move
    'Rename the tab
    ActiveSheet.Name = "export"

    'Save the WB as a CSV and close
    ActiveWorkbook.SaveAs FileName:="*path*\export", _
        FileFormat:=xlCSV, CreateBackup:=False, Local:=True
    ThisWorkbook.Saved = True
    ActiveWindow.Close
    Application.DisplayAlerts = True
    
End Sub

>Solution :

If you specify the file extension, this might solve your problem. Instead of using the default (now .CSV), try changing:

ActiveWorkbook.SaveAs FileName:="*path*\export"

to:

ActiveWorkbook.SaveAs FileName:="*path*\export.csv"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading