p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Microsoft Office > Excel VBA > Excel VBA
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 15th, 2006, 02:47 AM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Export spreasheet data to txt file

Dear all,
i had a macros to export spreadsheet info into txt.


The spreadsheet is below:
ID info
--- ----
KAS_1 123
KAS_2 456
TAS_1 789

what my script doing is combining data in the excel sheet into one txt file if the first 3 characters in ID column is the same.

The current ouput is:
KAS.txt
--------
1 is 123
2 is 456
(where 1 and 2 is the last character on ID)

TAS.txt
-------
1 is 789


Now , i wish to improve my txt file so that i will have string before and after the contain of the txt file. What should i do in order to get something like below??

Example:
KAS.txt
--------
Hello world 1
1 is 123
2 is 456
Hello world 2


note: the statement is the same for all the txt file.



##### my script #######




Option Explicit

Sub test()

Const startrow As Long = 2
Dim a As Long
Dim id_name As String, id As String, info As String
Dim temp As String


a = startrow
Do While Not ActiveSheet.Cells(a, "A").Value = ""
temp = ActiveSheet.Cells(a, "A").Value
id_name = Left(temp, 3)
id = Right(temp, Len(temp) - 4)
info = ActiveSheet.Cells(a, "B").Value

Call print_output(id, info, id_name)

a = a + 1
Loop

End Sub




Sub print_output(id, info, id_name)

Dim sPath As String

sPath = ThisWorkbook.Path & "/Test/" & id_name & ".txt"
'note use of append: "for output" will
' always overwrite the last item....
Open sPath For Append As #1
Print #1, id & " is " & info
Close #1
End Sub

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old May 18th, 2006, 10:12 AM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

 You can modify your code like

a = startrow

Call print_output("Hello World", 1, id_name)

Do While Not ActiveSheet.Cells(a, "A").Value = ""
temp = ActiveSheet.Cells(a, "A").Value
id_name = Left(temp, 3)
id = Right(temp, Len(temp) - 4)
info = ActiveSheet.Cells(a, "B").Value

Call print_output(id, info, id_name)

a = a + 1
Loop

Call print_output("Hello World", "2", id_name)

Regards,
Yogesh.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare Data in two txt file kiwibey ASP Forms 3 November 25th, 2004 02:43 PM
how to copy data from txt file kiwibey ASP Forms 2 November 23rd, 2004 02:11 PM
Read data from a text file (*.txt) adriant42 Excel VBA 2 June 4th, 2004 07:32 PM
export to .txt file meimy Pro VB.NET 2002/2003 0 May 31st, 2004 03:24 AM
saving vb.net form data as a .txt file rahul_salaria ASP Forms 0 April 20th, 2004 05:08 AM



All times are GMT -4. The time now is 07:57 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc