Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help - Can Excel create a text file??


Hi, Can we programme excel to create a Text file in the folder using
VBA? For example: I want to programme VBA to create a file call
Mysave.txt inside one of the folder? Can that be done?? Pls help me...
Thanks alot..


--
Acube
------------------------------------------------------------------------
Acube's Profile: http://www.excelforum.com/member.php...o&userid=29734
View this thread: http://www.excelforum.com/showthread...hreadid=494451

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Help - Can Excel create a text file??

Try something like the following:


Dim FName As String
Dim Ndx As Long
FName = "H:\Test\test.txt" '<< CHANGE
Open FName For Output As #1
For Ndx = 1 To 10
Print #1, Ndx
Next Ndx
Close #1


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Acube"
wrote in message
...

Hi, Can we programme excel to create a Text file in the folder
using
VBA? For example: I want to programme VBA to create a file call
Mysave.txt inside one of the folder? Can that be done?? Pls
help me...
Thanks alot..


--
Acube
------------------------------------------------------------------------
Acube's Profile:
http://www.excelforum.com/member.php...o&userid=29734
View this thread:
http://www.excelforum.com/showthread...hreadid=494451



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Help - Can Excel create a text file??

If you want to be a little more elegant this will present the typical
windows file dialog box. The user can input a new file name and then
write to the text stream.

Just presenting another option. Notice you have to refence the
Microsoft Scripting Runtime and I typically close the text stream before
exiting the module.

Option Explicit

' Requires Reference to Microsoft Scripting Rntime

Sub Test()

Dim fsoFileSystemObject As FileSystemObject
Dim strFileName As String
Dim tsTextStream As TextStream

Set fsoFileSystemObject = CreateObject("Scripting.FileSystemObject")
strFileName = Application.GetSaveAsFilename()
Set tsTextStream = fsoFileSystemObject.CreateTextFile(strFileName)

tsTextStream.WriteLine "Line 1"
tsTextStream.WriteLine "Line 2"
tsTextStream.WriteLine "Line 3"

tsTextStream.Close

End Sub




*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help - Can Excel create a text file??

Try this
ActiveCell.FormulaR1C1 = Range("A1")
ActiveCell.FormulaR1C1 = Range("A2")

Open "C\text.txt" For Append As #1
Write #1, Range("A1"),1Range("A2")
Close #1

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel - create a macro to use cell text as part of a file name bossman tv New Users to Excel 1 June 27th 06 10:38 PM
How to create a UTF-8 text file from excel VBA mah_kum_70 Excel Discussion (Misc queries) 1 April 29th 06 10:12 PM
Can I use Excel to create this text file? BigIan Excel Worksheet Functions 4 September 15th 05 03:06 PM
How to create text file from selected excel data Per Magnus L?vold Excel Programming 2 July 22nd 04 05:26 PM
Create and write a simple text file in Excel/VBA Thomas Wieser Excel Programming 4 April 13th 04 10:24 AM


All times are GMT +1. The time now is 12:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"