Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA Copy String into Single cell

Status
Not open for further replies.

kyletreyfield

Technical User
Jun 12, 2008
27
US
I need to copy a string of text into Excel that may contain spaces and chr(10) so I want it all in one cell.

Here is the code I've tried to use

Code:
STORE filetostr("c:\path\filename.txt") TO _cliptext
oSheet1.Select
oX.SendKeys("F2")
oSheet1.Paste
oX.SendKeys("Enter") 
 _cliptext = ""

Pastes into Excel fine but not all in one cell. What am I doing wrong?
 
Can you try:
oSheet1.range("A1").Paste()
or
oSheet1.range("A1").value=_cliptext

Should work.
 
Thanks, Ljupce. The paste has always worked,as it did now, but the problem is that I want the whole string to be pasted into one cell. When you do it manually, you can either double-click the cell, or press F2 (edit). I thought sendkeys would be the answer but I'm not even sure if sendkeys has any effect.
 
Hi,

Unless there is tab-chr(9) within the string it should fit into one cell. Can you try:

oSheet1.range("A1").value='^'+'"'+_cliptext+'"'

Thus we will force it (even if the string contains digits) to be accepted as a character string.

Any specific reason to use Paste() to populate single cell?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top