我正在尝试为powerpoint创建一个插件,让用户在下拉列表中选择一个目录,然后获取带有以列表视图形式显示的缩略图的powerpoint幻灯片列表。然后,用户应该能够选择缩略图并将幻灯片添加到他/她正在处理的当前演示文稿中。 (类似于直接从电源点访问的个人幻灯片库)。
我有填充列表框的通用代码。但得到一个我不知道如何解决的TypeError。
Private Sub CommandButton1_Click()
Dim fs, f, f1, fc, s As String
Dim folderspec As String
folderspec = "U:\PowerPointFiles\"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.SubFolders
ComboBox1.Clear
For Each f1 In fc
ComboBox1.AddItem f1.Name
Next f1
'ComboBox1.Activate --> doesnt' work
'Application.SendKeys "^{F4}" --> doesnt' work
End Sub
Private Sub ComboBox1_Change()
Dim fs, f, f1, MyFiles, s As String
Dim MyFolder As String
MyFolder = "U:\Methoden\power point trials\Addin Projekte\Slide Library Addin\" & ComboBox1
MyFiles = Dir(MyFolder & "\*.pptx")
ListView1.ListItems.Clear
Do While MyFiles <> ""
ListView1.ListItems.Add (MyFiles) --> Type mismatch
MyFiles = Dir
Loop
End Sub
结果应该是ListView中包含链接的.ppt文件列表。从这里我需要创建代码来添加缩略图。
抱歉...错过了您已经标记了问题代码行的事实。
我已经注释掉了几行原始代码并添加了一些细微的变化:
Private Sub CommandButton1_Click()
' You don't use all these variables, so no need to dim them here
' Dim fs, f, f1, MyFiles, s As String
Dim MyFiles As String
Dim MyFolder As String
'MyFolder = "U:\Methoden\power point trials\Addin Projekte\Slide Library Addin\" & ComboBox1
' Substituted a folder that exists on my system and changed the filespec
' form *.PPTX to *.* to ensure some results at my end while testing.
MyFolder = "C:\Temp"
MyFiles = Dir(MyFolder & "\*.*")
' ListView1.ListItems.Clear
ListBox1.Clear
Do While MyFiles <> ""
'ListView1.ListItems.Add (MyFiles) '--> Type mismatch
ListBox1.AddItem (MyFiles)
MyFiles = Dir
Loop
End Sub
我找到了解决方案:
Private Sub ComboBox1_Change()
Dim strLoad As String
Dim lvwItem As ListItem
Dim MyFolder As String
ListView1.ListItems.Clear
MyFolder = "U:\Methoden\power point trials\Addin Projekte\Slide Library Addin\" & ComboBox1
strLoad = Dir(MyFolder & "\*.*")
Do While strLoad > vbNullString
Set lvwItem = ListView1.ListItems.Add(, , strLoad)
strLoad = Dir
Loop
End Sub