Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Save Excel as .txt format.


Reply
 
Thread Tools Display Modes
  #1  
Old 05-30-2003, 03:56 AM
carnation's Avatar
carnation carnation is offline
Junior Contributor
 
Join Date: Apr 2003
Posts: 306
Default Save Excel as .txt format.


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?
Reply With Quote
  #2  
Old 06-01-2003, 12:26 PM
Michael_I Michael_I is offline
Contributor

* Expert *
 
Join Date: Dec 2001
Posts: 725
Default

This should work the same:

Code:
    ActiveWorkbook.SaveAs Filename:= _
        "C:\WINDOWS\Desktop\Book1.txt", FileFormat:=xlText, _
        CreateBackup:=False
You will need to change your variable names of course.

Mike
Reply With Quote
  #3  
Old 06-01-2003, 09:30 PM
bradac bradac is offline
Regular
 
Join Date: Sep 2001
Location: Mokane, MO
Posts: 98
Default

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
.txt into Excel with VB Dylan Johnson Word, PowerPoint, Outlook, and Other Office Products 3 05-21-2003 09:51 AM
Importing .txt File into Excel Template BiPolar1 Excel 4 03-13-2003 07:37 AM
file conversion from .doc word format to .txt format ashok General 2 10-21-2002 11:17 PM
Save in XLS format roglopes Word, PowerPoint, Outlook, and Other Office Products 7 05-16-2002 01:50 AM
save as in Excel pells Word, PowerPoint, Outlook, and Other Office Products 1 09-26-2001 04:30 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->