简体   繁体   English

使用VBA插入换行符(Alt + Enter)

[英]Insert a line break (Alt+Enter) with VBA

I have a VBA Macro for relacing a word with another one in Excel. 我有一个VBA宏,可以在Excel中将一个单词替换为另一个单词。

Call CharactersReplace(xRg, "Test1", "Test2", True)

It is working nicely but I want to do Alt + Enter on the cell of Excel (instead of Test2). 它工作正常,但我想在Excel的单元格上执行Alt + Enter (而不是Test2)。

Literally I want to do the line wrap within the cell. 从字面上看,我想在单元格中进行换行。

Example: 例:

From: Hey How are you? Test1 Bla Bla
To: Hey How are you?
Bla Bla

There is a code on VBA to do it? VBA上有代码可以执行此操作? I tried to do CHA(10) etc. but they are not working. 我试图做CHA(10)等,但是它们不起作用。

The vbLf or Chr(10) is the equivalent of a line break whithin a cell. vbLfChr(10)等效于单元格中的换行符。 So the following should work: 因此,以下应该工作:

Call CharactersReplace(xRg, "Test1", vbLf, True)

Also make sure that .WrapText of that cell is True . 另外,还要确保.WrapText该小区的是True

eg: Range("A1").WrapText = True otherwise you will insert a line break but won't see it. 例如: Range("A1").WrapText = True否则您将插入一个换行符但看不到它。

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

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