Drop xls ext

G

Guest

Hi Everybody, still trying to learn VB, but I can not find the answer to this.
My macro opens a .xls file and then afterwards saves it as a .csv, the
variable f has the File Name including the ext .xls, when saved I end up with
MyFile.xls.csv
How can I lose the xls ext?

Code Used

F = Application.GetOpenFilename("XL Files (*.xl*), *.XL*")
If F = False Then Exit Sub
Workbooks.Open F

ActiveWorkbook.SaveAs FileName:= _
"C:\...\" & F & ".csv", FileFormat _
:=xlCSV,

Many Thanks in anticipation
 
J

JE McGimpsey

One way:

If Right(F, 4) Like ".xl?" Then _
F = Left(F, LEN(F) - 4) & ".csv"
ActiveWorkbook.SaveAs _
FileName:="C:\\...\" & F, _
FileFormat:=xlCSV
 
G

Guest

Thanks JE it worked a treat.

JE McGimpsey said:
One way:

If Right(F, 4) Like ".xl?" Then _
F = Left(F, LEN(F) - 4) & ".csv"
ActiveWorkbook.SaveAs _
FileName:="C:\\...\" & F, _
FileFormat:=xlCSV
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top