Save Excel as .txt format.

carnation
05-30-2003, 03:56 AM
I have opened an excel file in VB code and I want to save it as a text file(as we can do in Microsoft Excel). How can I do that?

Michael_I
06-01-2003, 12:26 PM
This should work the same:


ActiveWorkbook.SaveAs Filename:= _
"C:\WINDOWS\Desktop\Book1.txt", FileFormat:=xlText, _
CreateBackup:=False


You will need to change your variable names of course.

Mike

bradac
06-01-2003, 09:30 PM
Here's the code I use to create a Workbook from a VB app:
----------------------------------------------------------------


Dim xlsfilename As String 'Needed for the Excel commands
Dim xlApp As excel.Application 'Needed for the Excel commands
Dim wkbNewBook As excel.Workbook 'Needed for the Excel commands
Dim wksSheet As excel.Worksheet 'Needed for the Excel commands

xlsfilename = App.Path & "\test.text"

'---- Creates a new hidden instance of Excel ----

Set xlApp = New excel.Application
Set wkbNewBook = xlApp.Workbooks.Add 'Creates the workbook
xlApp.ActiveSheet.Name = "test1" 'Creates a Worksheet called "test1"


'---- Do whatever you want in this section ----

Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
'Makes a ew sheet
Worksheets("Sheet2").Activate 'Makes sheet2 active
xlApp.ActiveSheet.Name = "Test2t" 'renames sheet2 to test2


'---- Save and Quit Excel ----
xlApp.DisplayAlerts = False 'Keeps any save popups from happening
ActiveWorkbook.Close SaveChanges:=True, FileName:=xlsfilename

xlApp.Quit '**Remember to close Excel!
Set wkbNewBook = Nothing
Set xlApp = Nothing

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum