代码的目标:
在 VBA 中创建一个 PowerPoint 加载项模块,用于搜索具有形状填充十六进制代码 #002466 的文本框,其中第一个字符是数字,第二个字符是句点。 然后,在同一张幻灯片中搜索高度超过 11 厘米且宽度超过 22 厘米的图像。 然后重新定位满足上述条件的文本框,使其左下角与满足图像条件的图像的左下角对齐。
额外信息:
PowerPoint 项目的宽度为 33.867 厘米,高度为 19.05 厘米。 所有幻灯片都是横向的,位置以厘米为单位,而不是点。 宏的所有安全设置已启用,其他子已在同一 PPT 中运行。
问题: 我运行代码但没有任何反应。没有错误,但也没有移动。
到目前为止的尝试: 我运行以下代码但没有任何反应;没有错误,但也没有重新定位。我也试过将厘米转换为点,但没有用。
我正在使用一些文本框来为屏幕截图添加标题,并且我已经编写了代码来重新着色这些有效的文本框。这是代码:
Option Explicit
Private Sub ChangeShapeFill()
Dim sld As Slide
Dim shp As Shape
Dim count As Integer
count = 0
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.Fill.ForeColor.RGB = RGB(20, 108, 253) Then
shp.Fill.ForeColor.RGB = RGB(0, 36, 102)
shp.Line.Weight = 1
shp.Line.ForeColor.RGB = RGB(255, 255, 255)
count = count + 1
End If
Next shp
Next sld
MsgBox "Updated " & count & " shapes.", vbOKOnly, "Shape Fill Update"
Beep
End Sub
这是我目前所拥有的:
Sub RepositionTextBoxes()
' Set variables for image size criteria
Const minWidth As Double = 22 ' cm
Const minHeight As Double = 11 ' cm
' Set variables for slide size
Const slideWidth As Double = 33.867 ' cm
Const slideHeight As Double = 19.05 ' cm
' Set variables for textbox fill color criteria
Const hexCode As String = "#002466"
Dim sld As Slide
Dim shp As Shape
Dim img As Shape
Dim txt As Shape
' Loop through each slide in the presentation
For Each sld In ActivePresentation.Slides
' Loop through each shape on the slide
For Each shp In sld.Shapes
' Check if shape is a textbox and has the correct fill color
If shp.Type = msoTextBox And shp.Fill.ForeColor.RGB = RGB(0, 36, 102) And _
IsNumeric(Mid(shp.Fill.ForeColor.RGB, 2, 1)) And _
Mid(shp.Fill.ForeColor.RGB, 3, 1) = "." Then
' Loop through each image on the slide
For Each img In sld.Shapes
If img.Type = msoPicture And img.Height / 28.3465 > minHeight And _
img.Width / 28.3465 > minWidth Then ' convert height and width to cm
' Reposition the textbox to align with the bottom-left corner of the image
Set txt = shp.Duplicate
txt.Left = img.Left
txt.Top = slideHeight - img.Top - img.Height
txt.Height = shp.Height
txt.Width = shp.Width
' Delete the original textbox
shp.Delete
' Exit the loop through images
Exit For
End If
Next img
End If
Next shp
Next sld
End Sub