如何在 PowerPoint 中使用 VBA 将用户窗体文本框中输入的变量获取到模块中的数组文本?

How to take variables entered in the userform text box to the array text in the module using VBA in PowerPoint?

我有一个 select 幻灯片的宏,其中包含必需的文本,用于移动到新的演示文稿。

我必须从 500 多张幻灯片演示文稿中提取 70-80 张幻灯片。但是我需要输入 VB/Module 来更改数组中的 keywords/search 文本。有什么方法可以将用户窗体中输入的文本移动到数组(文本)?

用户表单输入关键字。

如何link在代码中用数组列表输入文字?

Sub selct()

Dim pres1 As PowerPoint.Presentation, pres2 As PowerPoint.Presentation, 
pp  As Object
Set pp = GetObject(, "PowerPoint.Application")

Set pres1 = pp.ActivePresentation
Set pres2 = pp.Presentations.Add

Dim i As Long, n As Long
Dim TargetList

'~~>  Array of terms to search for
TargetList = Array("Agenda", "Review", "third", "etc")

'~~> Loop through each slide
For Each sld In pres1.Slides
    '~~> Loop through each shape
    For Each shp In sld.Shapes
        '~~> Check if it has text
        If shp.HasTextFrame Then
            Set txtRng = shp.TextFrame.TextRange

            For i = 0 To UBound(TargetList)
                '~~> Find the text
                Set rngFound = txtRng.Find(TargetList(i))

                '~~~> If found
                Do While Not rngFound Is Nothing
                    '~~> Set the marker so that the next find starts from here
                    n = rngFound.Start + 1
                    '~~> Chnage attributes
                    With rngFound.Font
                        .Bold = msoFalse
                        sld.Copy
                        pres2.Slides.Paste
                        '~~> Find Next instance
                        Set rngFound = txtRng.Find(TargetList(i), n)
                    End With
                Loop
            Next
        End If
    Next
Next
End Sub

即使表单未显示,也可以访问表单对象,如下所示:假设您有一个名为 UF1 的表单和一个名为 TBforKeyWord 的文本框,那么您可以访问文本框值在 UF1.TBforKeyWord,所以你可能

 Redim Preserve TargetList(Ubound(TargetList) + 1)
 TargetList(Ubound(TargetList) = UF1.TBforKeyWord

如果让用户输入多个关键字,逻辑是相同的,但是您需要在拆分(和解析)关键字方面做更多的工作。

编辑

 Dim text_array() As String 
 text_array = Split(SearchBox.Value, " ") 

 Dim iDimOld As Long
 Dim iDimNew As Long
 Dim i As Long

 iDimOld = Ubound(TargetList)
 iDimNew = iDimOld + Ubound(text_array) + 1
 Redim Preserve TargetList(iDimNew)


 ' Loop through each keyword in array 
 For i = 0 To Ubound(text_array)
      TargetList(iDimOld + i + 1) = text_array(i)
 Next