VBA - Save txt file as xls

lionelnz

Well-known Member
Joined
Apr 6, 2006
Messages
571
Hi all.

I want to use VBA to save a manually imported txt file as xls. This part of automating several functions as these functions are done several times a week on several files.

I have tried various SaveAs combinations but nothing seems to work.

Do I have to do something line this

Count Filename ( cFn, total characters in the txt file name)

fN = Left(Filename,cFn-4)

File SaveAs Filename=fN, Filetype = xlNormal

Thanks
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Workbooks.OpenText "H:\Desktop\MYFILE.txt"
Workbooks("MYFILE.txt").SaveAs "H:\Desktop\MYFILE.xls"
 
Upvote 0
Thanks I will give your simple solution a go but in the meantime I have worked out a more convoluted solution
Code:
 Sub FileSaveXls()
Dim strFileName As String
Dim cFn As Integer


strFileName = ActiveWorkbook.Name
cFn = Len(strFileName)
strFileName = Left(strFileName, cFn - 3) & "xls"
ActiveWorkbook.SaveAs Filename:=strFileName, FileFormat:=xlNormal
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top