943,929 Members | Top Members by Rank

Ad:
Apr 30th, 2009
0

relpacing blank spaces with comma

Expand Post »
hello frendz..

im working on a small application wher i need to copy the data from excel sheet and paste it to the text file.im trying to create a macro for tht.
the selected row should be in a specific format. like if ther r 3 colums then the text should be saved in text file with comma's like a,b,c.

uptil now, im able to save the file with the data which contains blank spaces. how can i remove those blank spaces and insert a comma ther i tried using the following code..but its not working..plz help me solve this prob??

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Open "C:\temp.txt" For Input As #1
  2. astring = Input$(LOF(1), 1)
  3. Close #1
  4.  
  5. astring = Replace(astring, " ", ",")
  6. MsgBox astring 'to check if values are correct
  7.  
  8. Open "C:\temp.txt" For Output As #1
  9. Print #1, astring
  10. Close #1

thnx in advance
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
love_dude1984 is offline Offline
92 posts
since Aug 2008
May 1st, 2009
0

Re: relpacing blank spaces with comma

You say you want to read from an Excel sheet to a text file, but your code shows you opening a text file for input. I don't know how you usually read from an Excel sheet, but I don't think you can open it like a text file as your code suggests...
Reputation Points: 13
Solved Threads: 17
Junior Poster
jonifen is offline Offline
152 posts
since Nov 2007
May 2nd, 2009
0

Re: relpacing blank spaces with comma

Perhaps those "spaces" you are talking about are actually "tab" characters. Try replacing with vbTab instead of " ".

Good Luck
Reputation Points: 156
Solved Threads: 296
Posting Virtuoso
vb5prgrmr is offline Offline
1,670 posts
since Mar 2009
May 4th, 2009
0

Re: relpacing blank spaces with comma

ya..vbTab works fine..thanks for the help
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
love_dude1984 is offline Offline
92 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: copying the data from Excel to text file
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Maze Game





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC