gpt4 book ai didi

vba - 简报 VBA : Search for an character Arrow and replace with a shape arrow

转载 作者:行者123 更新时间:2023-12-01 22:38:32 29 4
gpt4 key购买 nike

我需要做的是找到一个向上箭头字符并将其替换为向上箭头形状,并对向下箭头执行相同的操作。我是 VBA 的新手,但对我希望宏如何工作有一个想法。它应该循环遍历 powerpoint 上的所有幻灯片。

1) 找到箭头字符的位置? (使用 INSTR 命令?和 CHR 代码命令。不确定 INSTR 是否适用于 ppt 或此处是否合适的代码)

2) 使用从上一行代码返回的位置添加形状。我的代码如下,已经将此形状添加到我的规范中。

  Dim i As Integer
Dim shp As Shape
Dim sld As Slide
Set sld = Application.ActiveWindow.View.Slide

Set shp = sld.Shapes.AddShape(36, 10, 10, 5.0399, 8.6399)
shp.Fill.ForeColor.RGB = RGB(89, 0, 0)
shp.Fill.BackColor.RGB = RGB(89, 0, 0)
shp.Line.ForeColor.RGB = RGB(89, 0, 0)

3) 查找并删除所有字符箭头,这样就只剩下形状了。

我一直在努力学习 PPT 中的 VBA,如果您能给我任何帮助,我将不胜感激。

最佳答案

您走在正确的轨道上。假设我有一个像这样的形状,其中有字母和一个特殊字符,由十六进制值 &H25B2 表示。

enter image description here

首先,您需要确定您角色的值(value)是什么。您可以在很多地方找到这些引用资料。

然后,如何在您的代码中使用,这是一个找到形状并用箭头覆盖它的示例,根据@SteveRindsberg 的建议进行了修改,如下:)

Public Const upArrow As String = &H25B2     'This is the Hex code for the upward triangle/arrow
Public Const downArrow As String = &H25BC 'This is the Hex code for the downward triangle/arrow
Sub WorkWithSpecialChars()
Dim pres As Presentation
Dim sld As Slide
Dim shp As Shape
Dim foundAt As Long
Dim arrowTop As Double
Dim arrowLeft As Double
Dim arrow As Shape
Set pres = ActivePresentation

For Each sld In pres.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
foundAt = InStr(shp.TextFrame.TextRange.Characters.Text, ChrW(upArrow))
If foundAt > 0 Then
MsgBox "Slide " & sld.SlideIndex & " Shape " & shp.Name & " contains " & _
"the character at position " & foundAt, vbInformation

'Select the text
With shp.TextFrame.TextRange.Characters(foundAt, 1)
'Get the position of the selected text & add the arrow
Set arrow = sld.Shapes.AddShape(36, _
.BoundLeft, .BoundTop, .BoundWidth, .BoundHeight)
'additional code to format the shape
' or call a subroutine to format the shape, etc.


End With
Else:
Debug.Print "Not found in shape " & shp.Name & ", Slide " & sld.SlideIndex
End If
End If
Next
Next

End Sub

关于vba - 简报 VBA : Search for an character Arrow and replace with a shape arrow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19275669/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com