excel - 从包含文本框和表格的 PowerPoint 幻灯片中提取文本以粘贴到 Excel 工作表中
问题描述
我是 Excel vba 的新手,并试图调整下面的代码以从 PPT 文件中提取文本并将所有文本粘贴到 Excel 工作表中。从带有表格的幻灯片中提取数据的代码已经工作,但它无法从文本框或幻灯片标题中提取数据。源文件的前 2 张 PPT 幻灯片不包含任何表格。感谢您对此的帮助。
Sub DataTransfer()
Dim shp As Shape, i%, j%
Dim colCount As Integer
Dim rowCount As Integer
Dim rowNum As Integer
Dim rng As Object
Set rng = GetObject(, "Excel.Application").Range("A1") ' start at top of worksheet
For i = 1 To ActivePresentation.Slides.Count
For Each shp In ActivePresentation.Slides(i).Shapes
If shp.HasTextFrame Then
If shp.Type = msoTextBox Then
rng.Value = shp.Shapes.TextFrame.TextRange
Set rng = rng.Offset(rowNum + 1) ' 1 blank row between tables
End If
End If
Next shp
Next i
For i = 3 To ActivePresentation.Slides.Count
For Each shp In ActivePresentation.Slides(i).Shapes
If shp.HasTable Then
With shp.Table
colCount = .Columns.Count
rowCount = .Rows.Count
On Error Resume Next
For rowNum = 0 To .Rows.Count - 1
For j = 0 To 7
rng.Offset(rowNum, j).Value = (.Cell(rowNum + 1, j + 1).Shape.TextFrame.TextRange)
Next j
'rng.Offset(rowNum, 4).Interior.Color = (.Cell(rowNum + 1, 5).Shape.TextFrame.TextRange)
Next rowNum
Set rng = rng.Offset(rowNum + 1) ' 1 blank row between tables
End With
End If
Next shp
Next i
结束子
解决方案
试试这个来提取文本而不是上面的内容:
For i = 1 To ActivePresentation.Slides.Count
For Each shp In ActivePresentation.Slides(i).Shapes
If shp.HasTextFrame Then
' Shapes other than textbox types can contain text
If shp.TextFrame.HasText Then
rng.Value = shp.TextFrame.TextRange.Text
Set rng = rng.Offset(rowNum + 1) ' 1 blank row between tables
End If
End If
Next shp
Next i
推荐阅读
- python - 如何计算 Django 中所有客户的剩余金额?
- java - 简单的java程序返回不正确的值
- python - For 循环遍历两个数据帧以从一个 df 中提取项目并将其存储在另一个
- javascript - JSON 错误中出现意外的令牌,但我使用的是“produces = “text/plain””?
- python - Django,根据来自另一个模型的值创建自定义订单/过滤器
- codeigniter - 如何在 CodeIgniter 3 中下载生成的 PDF?
- nginx - 我如何从基本 url 重写/重定向以在 NGINX 中指定 localhost url?
- clickhouse - clickhouse 设置中的 max_concurrent_queries_for_all_user 和 max_concurrent_queries 有什么区别?
- excel - Excel中单元格值的点运算
- html - 定位和响应问题