Hi All,

I have a macro for embedding every cell in double quotes and then converting Excel to CSV.
The CSV file should have the same name as the excel file.
However since my excel file name contains "." in between,
ex : Test1.Test2.xlsx , i am not getting the CSV file to have the same name as excel

My objective is if the excel name is Test1.Test2.xlsx then the CSV file name should be Test1.Test2.csv

here is the macro,

Sub WrapInQuotes()
Dim TheFileSaveName As String, vFileNum As Integer, qcq As String, tempStr As String
Dim tempStr2 As String
Dim i As Long, j As Integer
Dim TheFileName As String
Dim InitFileName As String


TryAgain:
TheFileName = ActiveWorkbook.Name
If InStr(TheFileName, ".") = 0 Then TheFileName = TheFileName & ".csv"

InitFileName = Left(TheFileName, InStr(TheFileName, ".") - 1) _
& "D" & Format(Date, "yyyymmdd") & "T" & Format(Time, "hhmmss")

TheFileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitFileName, _
Filefilter:="CSV (Comma delimited) (*.csv), *.csv", _
Title:="Please enter filename to export to")

If TheFileSaveName = "False" Then End

vFileNum = FreeFile()
On Error Resume Next
Open TheFileSaveName For Output As #vFileNum
If Err <> 0 Then MsgBox "Cannot save to filename " & TheFileSaveName: End
On Error GoTo 0

qcq = Chr(34) & Chr(44) & Chr(34)

For i = 1 To [a1].SpecialCells(xlLastCell).Row
For j = 1 To Cells(i, 256).End(xlToLeft).Column
tempStr2 = Cells(i, j).Text
If j = 1 Then
tempStr = RTrim(tempStr2)
Else
tempStr = tempStr & qcq & RTrim(tempStr2)
End If
Next j
Print #vFileNum, Chr(34) & tempStr & Chr(34)
Next i

Close #vFileNum

End Sub

Can anyone please help me on this ?