通过代码在包装的单元格中插入换行符 [英] Insert line break in wrapped cell via code

查看:78
本文介绍了通过代码在包装的单元格中插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过VBA代码在换行单元格中插入换行符? (类似于 Alt - 手动输入数据时输入

Is it possible to insert line break in a wrapped cell through VBA code? (similar to doing Alt-Enter when entering data manually)

我已将单元格的换行文本属性设置为真的通过VBA代码,我也通过VBA代码插入数据。

I have set the cell's wrap text property to True via VBA code, and I am inserting data into it also through VBA code.

推荐答案

是的。 Alt 输入的VBA是使用换行符:

Yes. The VBA equivalent of AltEnter is to use a linebreak character:

ActiveCell.Value = "I am a " & Chr(10) & "test"

请注意,这会自动设置 WrapText 到True。

Note that this automatically sets WrapText to True.

证明

Sub test()
Dim c As Range
Set c = ActiveCell
c.WrapText = False
MsgBox "Activcell WrapText is " & c.WrapText
c.Value = "I am a " & Chr(10) & "test"
MsgBox "Activcell WrapText is " & c.WrapText
End Sub

这篇关于通过代码在包装的单元格中插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆