excel - 有没有办法将多个数据结果返回到一个单元格中?
问题描述
我正在构建一个代码来从多个文档中检索所有文本,然后将该文档的文件名放在 A 列中,然后将该文档中包含的所有文本放在同一行中,但在 B 列中。现在,我有代码到我可以从这些文档中检索文本的位置,但我的问题是我无法将所有文本条目合并到一个单元格中。每个文档包含不同数量的文本条目,因此代码必须将所有文本包含在一个单元格中。
这是我到目前为止所拥有的:
Dim ent As AXDBLib.AcadEntity
Dim txt As AcadText
Dim mtxt As AcadMText
Dim textValue As String
For Each ent In ActiveDocument.ModelSpace
If TypeOf ent Is AcadText Then
Set txt = ent
Cells(4, 2) = txt.TextString
Debug.Print txt.TextString
End If
解决方案
请尝试下一个方法:
Sub testAllInACell()
'your existing code...
For Each ent In ActiveDocument.ModelSpace
If TypeOf ent Is AcadText Then
Set txt = ent
If textvalue = "" Then
textvalue = txt.TextString
Else
textvalue = textvalue & vbLf & txt.TextString
End If
End If
Next
If Len(textvalue) <= 32767 Then
Cell(4, 2).value = textvalue
Else
MsgBox "The text to be copied exceeds the maximum allowed... " & vbCrLf & _
"(" & Len(textvalue) & " against 32767, admitted)"
End If
'Your existing code (if any...)
End Sub
推荐阅读
- python - 让 pandas plot() 显示 xlabel 和 xvalues
- python - 来自探索端点但不是来自搜索端点的 Foursquare API 列表
- r - 修改函数以添加对特定值的额外搜索
- ios - 在 iOS/macOS 上处理弃用的现代方法
- here-api - 使用此处 API 按类别名称搜索
- docker - 我可以在不声明 indv 的情况下将所有现有的环境变量传递给图像吗?
- sql-server - 如何将聚合函数 MAX 与 SELECT * 一起使用?
- sql - SQL 嵌套聚合函数
- java - 使用递归确定位数
- javascript - 如何使用 Puppeteer 从输入中删除现有文本?