Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.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
Arrays 如何使用PowerPoint中的VBA将用户表单文本框中输入的变量转换为模块中的数组文本?_Arrays_Vba_Powerpoint_Userform - Fatal编程技术网

Arrays 如何使用PowerPoint中的VBA将用户表单文本框中输入的变量转换为模块中的数组文本?

Arrays 如何使用PowerPoint中的VBA将用户表单文本框中输入的变量转换为模块中的数组文本?,arrays,vba,powerpoint,userform,Arrays,Vba,Powerpoint,Userform,我有一个宏来选择幻灯片和所需的文本,以移动到新的演示文稿 我必须从500多张幻灯片中提取70-80张幻灯片。但是我需要输入VB/Module来更改数组中的关键字/搜索文本。有没有办法将在userform中输入的文本移动到数组(text)中 Userform输入关键字。 如何将输入的文本与代码中的数组列表链接 Sub selct() Dim pres1 As PowerPoint.Presentation, pres2 As PowerPoint.Presentation, pp As O

我有一个宏来选择幻灯片和所需的文本,以移动到新的演示文稿

我必须从500多张幻灯片中提取70-80张幻灯片。但是我需要输入VB/Module来更改数组中的关键字/搜索文本。有没有办法将在userform中输入的文本移动到数组(text)中

Userform输入关键字。

如何将输入的文本与代码中的数组列表链接

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

非常感谢你的友好回复。请注意,我只是VBA的初学者。我知道这项工作的目标,但我自己还没有练习编写代码。考虑到工作中的紧迫性,我只是试图找到可用的代码,并用我目前有限的知识编辑尽可能多的代码。我看到下面的代码帮助我分割关键字。你能帮我把你的代码和这个添加到第一个模块中吗(在VB模式下手动输入关键字)?Private Sub SearchButton_Click()Dim text_array()作为字符串Dim关键字作为变量“将所有关键字保存到文本_array”使用拆分从搜索框中提取单词,用空格分隔text\u array=Split(SearchBox.Value,“”)循环数组中的每个关键字,查找text\u array中的每个关键字“显示关键字在数组中MsgBox(关键字)”在此处使用关键字进行搜索。。。下一站谢谢您的友好回复。我会让你知道我的进展。