Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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中向PPT 2010中的文本框添加多行_Vba_Powerpoint - Fatal编程技术网

在VBA中向PPT 2010中的文本框添加多行

在VBA中向PPT 2010中的文本框添加多行,vba,powerpoint,Vba,Powerpoint,我试图引用一个文本框(名为WarningText1),并根据用户在GUI中选择的内容输出多行文本。这就是我正在尝试的: Private Sub WarningInfo() Call Dictionary.WarningInfo Call Dictionary.WindInfo 'Sets the font for the warning information text. With ActiveWindow.Selection.SlideRange.Shap

我试图引用一个文本框(名为WarningText1),并根据用户在GUI中选择的内容输出多行文本。这就是我正在尝试的:

Private Sub WarningInfo()
    Call Dictionary.WarningInfo 
    Call Dictionary.WindInfo 

    'Sets the font for the warning information text.
    With ActiveWindow.Selection.SlideRange.Shapes("WarningText1").TextFrame2.TextRange.Font 
        .Size = 24 
        .Name = "Aharoni" 
        .Shadow.Visible = True 
    End With 

    ComboBoxList = Array(CStr(ComboBox2), CStr(ComboBox3), CStr(ComboBox4), CStr(ComboBox5), CStr(ComboBox6)) 

    For Each Ky In ComboBoxList 
        On Error Resume Next 
         'If nothing is selected in all dropdowns, do nothing and exit this sub.
        If ComboBox2 = "" And ComboBox3 = "" And ComboBox4 = "" And ComboBox5 = "" And ComboBox6 = "" Then 
            Exit Sub 
             'Otherwise, if even one dropdown has a selection, insert selected text.
        Else 
            ActiveWindow.Selection.SlideRange.Shapes("WarningText1").TextFrame2.TextRange.Text = dict2.Item(Ky)(0) & dict3.Item(Ky)(0) 
        End If 
    Next 

    Set dict2 = Nothing 

End Sub 
当我使用dict2或dict3行运行这行代码时,它工作得非常好。但它似乎无法以这种方式将它们相加

运行时,我得到错误:“类型不匹配”

另外,当我放置
dict2.Item(Ky)(0)和dict2.Item(Ky)(0)
(相同的事情两次)时,它会工作

我假设有一个简单的解决方案,但我似乎在网上的任何地方都找不到。谢谢你的帮助

*****编辑*****

我添加了代码来帮助调试。这是在不工作的行之前添加的:

Debug.Print dict2.Item(Ky)(0)
Debug.Print dict3.Item(Ky)(0)
这两个值都打印出了它们应该显示的内容。它只是不会将它们都添加到同一个文本框中

****编辑2****

正如您在上面的代码中所看到的,我正在将我的字典调用到此Sub中。以下是我的字典的代码:

Option Private Module 'This is necessary so that these modules do not show up in the PPT Macro window.
Public dict, dict2, dict3 As Object, Key, val 'Makes the dictionaries public so they can be accessed by other Modules.

Sub WarningInfo()

'This is the dictionary for the maximum expected hail size.

Set dict2 = CreateObject("Scripting.Dictionary")

Key = "No Hail": val = Array("No hail expected")
dict2.Add Key, val
Key = "0.25""": val = Array("Hail: Up to 0.25""")
dict2.Add Key, val
Key = "0.50""": val = Array("Hail: Up to 0.50""")
dict2.Add Key, val

End Sub

Sub WindInfo()

'This is the dictionary for the maximum expected wind speed.

Set dict3 = CreateObject("Scripting.Dictionary")

Key = "35 mph": val = Array("Wind: Up to 35 mph")
dict3.Add Key, val
Key = "40 mph": val = Array("Wind: Up to 40 mph")
dict3.Add Key, val
Key = "45 mph": val = Array("Wind: Up to 45 mph")
dict3.Add Key, val

End Sub
字典是我设置变量dict2和dict3的地方

谢谢


Cory

如果您的问题是如何将两个条目放在两行中,请在它们之间插入一个vbCrLf:
dict2.Item(Ky)(0)&vbCrLf&dict3.Item(Ky)(0)
Andre,我不需要,但谢谢。当我按照上面代码所示运行它时,我得到一个类型不匹配错误。不知道为什么。这是一个相当相关的信息,不是吗?请把它添加到问题中。对不起,是的。我只是注意到,因为我注释掉了“下一步继续出错”。另外,当我放置
dict2.Item(Ky)(0)和dict2.Item(Ky)(0)
(同样的事情两次)时,它也能工作。您有声明变量的代码吗?另外,在VBA中,最好的编程实践是在代码中添加以下第一行,首先是所有过程:Option Explicit,然后声明所有变量。这将为您节省大量调试时间。所以我看不出dict2.Item(Ky)(0)应该返回什么数据类型。我也看不到您在哪里设置对dict2对象(或dict3)的引用,即使您在最后一行中清除了它。