简体   繁体   English

从Excel单元格复制时删除段落标记

[英]Remove paragraph mark when copying from excel cell

Please help me copy a string from a listbox when a user hits ctrl+c. 当用户按下ctrl + c时,请帮助我从列表框中复制字符串。 I was using the dataobject but for some reason this worked perfectly some times and gave me an error message other times. 我正在使用数据对象,但由于某种原因,它有时可以完美地工作,而有时却给我一条错误消息。 If you know why this is, stop reading, as the rest of this question is not necessary. 如果您知道这是为什么,请停止阅读,因为该问题的其余部分没有必要。

Now I am putting this in a worksheet cell and using range.copy, however, when the string is pasted into a textbox, it retains the paragraph mark that excel seems to put at the end of every cell! 现在,我将其放置在工作表单元格中并使用range.copy,但是,当字符串粘贴到文本框中时,它保留了excel似乎放在每个单元格末尾的段落标记! Just to make things fun, the paragraph mark cannot be removed by using Left() - it takes everything but the paragraph mark. 只是为了使事情变得有趣,不能使用Left()删除段落标记-它需要除段落标记之外的所有内容。 (Paragraph mark below is represented by P ). (下面的段落标记由P表示)。

s = "stringP"
s = Left(s,len(s)-1)
print s

returns: strinP 返回:strinP

Has to be something simple I'm missing. 一定是我缺少的简单事物。

Have you tried trim() function ? 您是否尝试过trim()函数? And why do you have to use Range.copy ? 以及为什么必须使用Range.copy

Can't you just assign textbox1.value = Range("A1") ? 您不能只分配textbox1.value = Range("A1")吗? It works fine without any bugs. 它工作正常,没有任何错误。

I haven't tested this but have you tried chopping two characters? 我没有测试过,但是您尝试过切两个字符吗?

I'm sure it's \\r\\n or carriage-return + line feed, not just \\n you need to chop. 我确定它是\\r\\n或回车+换行符,而不仅仅是\\n您需要砍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM