从 VBA 表单插入值时,将 Excel 电子表格值设置为自动换行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13108594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set Excel spreadsheet values to wrap text automatically when inserting values from VBA form
提问by methuselah
I'm currently inserting some values into an Excel spreadsheet via a VBA form. What I've done is working great so far but I was wondering if there was a way to set the text to automatically wrap in each cell?
我目前正在通过 VBA 表单将一些值插入到 Excel 电子表格中。到目前为止,我所做的一切都很好,但我想知道是否有办法将文本设置为自动换行到每个单元格中?
As right now it seems like everything will just overlap with each other.
就像现在一样,一切似乎都会相互重叠。
Private Sub btnSubmit_Click()
Dim ws As Worksheet
Dim rng1 As Range
Set ws = Worksheets("main")
Set rng1 = ws.Cells(Rows.Count, "a").End(xlUp)
rng1.Offset(1, 0) = cbo_deptCode.Value
End Sub
回答by Dave Lewis
Try
尝试
With rng1.Offset(1, 0)
.Value = cbo_deptCode.Value
.WrapText = True
End With