Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - saving strings to a text file

Is there any Excel VBA code to save strings to a text file?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default VBA - saving strings to a text file

Look for the Open statement, whose See Also link should lead you to Close,
Print, Write, and even Input and Read.

--

--Andy Smith



"JohnJ" wrote:

Is there any Excel VBA code to save strings to a text file?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA - saving strings to a text file

Try code like the following to get started:

Dim FName As String
Dim FNum As Integer
Dim S As String

FName = "C:\Test\TestFile.txt"
FNum = FreeFile
S = "Write This"
Open FName For Output Access Write As #FNum
Print #FNum, S
Close #FNum


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"JohnJ" wrote in message
...
Is there any Excel VBA code to save strings to a text file?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA - saving strings to a text file

I should have noted that if you open the file for Output, the existing
contents of the file are destroyed. To keep the existing content, open for
Append:

Open FName For Append Access Write As #FNum

This will cause the data to be written at the end of the existing contents.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"Chip Pearson" wrote in message
...
Try code like the following to get started:

Dim FName As String
Dim FNum As Integer
Dim S As String

FName = "C:\Test\TestFile.txt"
FNum = FreeFile
S = "Write This"
Open FName For Output Access Write As #FNum
Print #FNum, S
Close #FNum


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"JohnJ" wrote in message
...
Is there any Excel VBA code to save strings to a text file?





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
find and replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
Saving multi-tab excel file created from comma delimited text file Marcus Aurelius Excel Programming 2 December 19th 05 05:16 PM
Clean up strings before creating a text file quartz[_2_] Excel Programming 9 October 7th 05 06:52 PM
Writing strings to a text file ? Dan Thompson Excel Programming 3 September 23rd 04 07:17 PM
import text-file - strings contain cr-lf John A Grandy Excel Programming 2 August 25th 03 06:38 PM


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

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

About Us

"It's about Microsoft Excel"