作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 excel 2010 VBA (7.0) 上创建了一个用户表单
,它将传输用户通过.GetOpenFileName
属性选择的文件。然后将所选文件的文件路径插入到 ListBox
我的问题是目前我正在尝试使用 MultiSelect
,但是当我为 .GetOpenFileName
提供 Multiselect
属性来发送我的 ListBox
的文件路径(启用了多行) 我遇到了 GetOpenFileName
代码行显示的类型不匹配错误。代码示例如下:
Private Sub CommandButton1_Click ()
Dim strFilePath As String
StrFilePath = Application.GetOpenFilename (,,,, MultiSelect:= True)
If strFilePath = "False" Then Exit Sub
FilesFrom.Value = strFilePath
End Sub
FilesFrom 是我想要进入的文件路径的列表框。我的代码可以允许用户选择单个文件并传输该文件,但它不允许我用多个文件路径填充此列表框。
关于如何允许用户选择多个文件并将文件路径插入名为 FilesFrom 的列表框的任何想法?
最佳答案
问题是 MultiSelect
返回一个 Array
。
下面的代码应该正是您想要的。它适合多选或单选。
Private Sub CommandButton1_Click()
'GetOpenFile MultiSelect will return an Array if more than one is selected
Dim FilePathArray As Variant
FilePathArray = Application.GetOpenFilename(, , , , MultiSelect:=True)
If IsArray(FilePathArray) Then
Dim ArraySize As Long
ArraySize = UBound(FilePathArray, 1) - LBound(FilePathArray, 1) + 1
Dim ArrayPosition As Long
For ArrayPosition = 1 To ArraySize
If Not FilePathArray(ArrayPosition) = Empty Then
'Replace "UserForm1" with the name of your Userform
UserForm1.FilesFrom.AddItem (FilePathArray(ArrayPosition))
End If
Next ArrayPosition
ElseIf FilePathArray <> False Then
'Replace "UserForm1" with the name of your Userform
UserForm1.FilesFrom.AddItem (FilePathArray)
End If
End Sub
关于vba - VBA 中 .GetOpenFileName 的多选错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35626944/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!