I am using Microsoft Visual Basic for Application. Here I want to store my data into a .csv file.
Dim FileName As String
Dim PathName As String
Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets("Sheet1")
FileName = "filename.csv"
PathName = Application.ActiveWorkbook.Path
ws.Copy
ActiveWorkbook.SaveAs FileName:=PathName & "\" & FileName, _
FileFormat:=xlCSV, CreateBackup:=False
By using the code we can convert the data to .csv file.
Error:Method 'Sheets' of object '_Global' failed
This is the error because there is no worksheets are active. But when I use this macros in Excel it will work. But I'm using it in Microsoft Visual Basic for Applications in CATIA. So I don't wanna introduce Excel variable here. It cause some compatibility issue. So please help me to create a csv file in VBA? Thanks in Advance.