【发布时间】:2020-10-01 18:26:36
【问题描述】:
我正在尝试修改下面现有的 PowerPoint VBA 代码,以包括除了列出的其他属性之外的形状文本。此代码的目的是从 PowerPoint 中提取每个形状/文本框及其属性并将其转储到表格中。
我添加的行就在下面,我尝试了 oSh.TextFrame oSh.TextRange 和没有运气的组合。它返回一个有标题但完全空白的文件。知道我做错了什么以及为什么这不起作用吗?
& oSh.Text & vbTab _
完整代码:
Sub ExportCoords()
Dim oSlides As Slides
Dim oSl As Slide
Dim oSh As Shape
Dim strOutput As String
Dim strFileName As String
Dim intFileNum As Integer
Dim lngReturn As Long
' Get a filename to store the collected text
strFileName = InputBox("Enter the full path and name of file to save info to", "Output file?")
' did user cancel?
If strFileName = "" Then
Exit Sub
End If
' is the path valid? crude but effective test: try to create the file.
intFileNum = FreeFile()
On Error Resume Next
Open strFileName For Output As intFileNum
If Err.Number <> 0 Then ' we have a problem
MsgBox "Couldn't create the file: " & strFileName & vbCrLf _
& "Please try again."
Exit Sub
End If
Close #intFileNum ' temporarily
strOutput = "Slide" & vbTab & "Name" & vbTab & "Text" & vbTab & "Type" _
& vbtab & "Left" & vbTab & "Top" & vbTab & "width" _
& vbTab & "height" & vbCrLf
' Get the info
Set oSlides = ActivePresentation.Slides
For Each oSl In oSlides
For Each oSh In oSl.Shapes
strOutput = strOutput _
& oSl.SlideIndex & vbTab _
& oSh.Name & vbTab _
& oSh.Text & vbTab _
& osh.Type & vbtab _
& oSh.Left & vbTab _
& oSh.Top & vbTab _
& oSh.width & vbTab _
& oSh.height & vbCrLf
Next oSh
Next oSl
' now write the text to file
Open strFileName For Output As intFileNum
Print #intFileNum, strOutput
Close #intFileNum
' show what we've done
lngReturn = Shell("NOTEPAD.EXE " & strFileName, vbNormalFocus)
End Sub
【问题讨论】:
标签: vba powerpoint