Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba VB.Net VSTO PowerPoint加载项_Vba_Vsto_Powerpoint_Powerpoint 2013 - Fatal编程技术网

Vba VB.Net VSTO PowerPoint加载项

Vba VB.Net VSTO PowerPoint加载项,vba,vsto,powerpoint,powerpoint-2013,Vba,Vsto,Powerpoint,Powerpoint 2013,我正在为PowerPoint 2013制作一个外接程序。我的目标是将我在幻灯片上找到的所有方程式转换为普通文本,以更改这些方程式的字体。 因为当它们是方程式时,它不会让我改变字体。我通过迭代文本范围和查找字体名称,找到了公式,它们使用“Cambria Math”。所以我的问题是如何通过编程将公式更改为普通文本,就像公式工具中的按钮一样?似乎出于某种原因,他们从PowerPoint中删除了“录制宏”,所以我无法从中获得帮助。 我试着在word中录制宏并做同样的事情,结果得到:Selection.O

我正在为PowerPoint 2013制作一个外接程序。我的目标是将我在幻灯片上找到的所有方程式转换为普通文本,以更改这些方程式的字体。 因为当它们是方程式时,它不会让我改变字体。我通过迭代文本范围和查找字体名称,找到了公式,它们使用“Cambria Math”。所以我的问题是如何通过编程将公式更改为普通文本,就像公式工具中的按钮一样?似乎出于某种原因,他们从PowerPoint中删除了“录制宏”,所以我无法从中获得帮助。 我试着在word中录制宏并做同样的事情,结果得到:
Selection.OMaths(1).ConvertToMathText
,但在PowerPoint中似乎不是OMaths

Dim Application As PowerPoint.Application = New PowerPoint.Application
        Dim Presentation As PowerPoint.Presentation = Application.ActivePresentation
        Dim Windows As PowerPoint.DocumentWindows = Application.Windows

        For Each Slide As PowerPoint.Slide In Presentation.Slides
            For Each Shape As PowerPoint.Shape In Slide.Shapes
                For Each Paragraph As PowerPoint.TextRange In Shape.TextFrame.TextRange
                    For Each Line As PowerPoint.TextRange In Paragraph.Lines
                        If Line.Font.Name = "Cambria Math" Then
                            With Line.Font
                                .Name = "Calibri"
                                .Bold = True
                            End With
                        ElseIf Line.Font.Name = "Calibri" Then
                            With Line.Font
                                .Name = "Palatino"
                            End With
                        End If
                    Next Line
                Next Paragraph
            Next Shape
            Next Slide
    End Sub
此处的其他文本通常会更改,但带有“Math Cambria”字体的文本保持不变

我还尝试了选择,然后是Omath,比如在Word Vsto中,但似乎Omath不是PowerPoint的一部分。下一个代码实际上应该把它改成等式,但我想如果它起作用,可能会找到一种方法来逆转它

For Each Window As PowerPoint.DocumentWindow In Windows
    Selection.OMaths(1).ConvertToMathText
Next Window

我将其用于VBA中的PowerPoint 2016。我的字体列表中没有“Calibri”,所以我把它改成了“Calibri(Body)”,它就可以工作了。这可能与您在.NET VSTO加载项中遇到的问题相同。如果我有时间,我将构建一个VSTO插件的示例,并发布结果

视频

VBA代码
@我编辑了这个问题,希望它能让问题更清楚。不用担心,伙计:)
Public Sub UpdateShapeFont()
On Error GoTo ErrTrap
Dim Application     As PowerPoint.Application: Set Application = New PowerPoint.Application
Dim Presentation    As PowerPoint.Presentation: Set Presentation = Application.ActivePresentation
Dim Windows         As PowerPoint.DocumentWindows: Set Windows = Application.Windows
Dim Slide           As PowerPoint.Slide
Dim Shape           As PowerPoint.Shape
Dim Paragraph       As PowerPoint.TextRange
Dim line            As PowerPoint.TextRange

    For Each Slide In Presentation.Slides
        For Each Shape In Slide.Shapes
            For Each Paragraph In Shape.TextFrame.TextRange
                For Each line In Paragraph.Lines
                    Select Case line.Font.Name
                        Case "Cambria Math"
                            With line.Font
                                .Name = "Calibri (Body)" 'check if the font exists in your list of fonts; it did not work for "Calibri"
                                .Bold = True
                            End With
                        Case "Calibri"
                            With line.Font
                                .Name = "Palatino"
                            End With
                    End Select
                Next line
            Next Paragraph
        Next Shape
    Next Slide
            
ExitProcedure:
    On Error Resume Next
    Exit Sub

ErrTrap:
    Select Case Err.number
        Case Else
            Debug.Print "Error #: " & Err.number & " |Error Description: " & Err.description
    End Select
    Resume ExitProcedure
    Resume 'for debugging
    
End Sub