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??

Open "C:\temp.txt" For Input As #1
 astring = Input$(LOF(1), 1)
Close #1

astring = Replace(astring, " ", ",")
MsgBox astring 'to check if values are correct

Open "C:\temp.txt" For Output As #1
Print #1, astring
Close #1

thnx in advance

Recommended Answers

All 3 Replies

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...

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

Good Luck

ya..vbTab works fine..thanks for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.