【发布时间】:2014-12-15 06:24:09
【问题描述】:
使用它从特定文件夹中获取 excel 文件。 它在 windows 操作系统中工作,但在 Mac 操作系统中不工作。 如何使其成为交叉板形式?请帮忙。
Sub getfilename()
Dim objFSO As Object
Dim intCountRows As Integer
Application.FileDialog(msoFileDialogFolderPicker).Title = _
"Select a Path"
intResult = Application.FileDialog( _
msoFileDialogFolderPicker).Show
If intResult <> 0 Then
strpath = Application.FileDialog(msoFileDialogFolderPicker _
).SelectedItems(1)
Set objFSO = CreateObject("Scripting.FileSystemObject")
ThisWorkbook.Activate
Sheets("dropdown").Select
Range("q2").Value = strpath
End If
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strpath)
ThisWorkbook.Activate
Sheets("dropdown").Activate
Range("aa3:aa2000").Clear
i = 1
For Each objFile In objFolder.Files
Filename = objFile.Name
Range("aa1000").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Application.ActiveCell = Filename
Next objFile
End Sub
【问题讨论】:
-
哪里出错了?
-
Scripting.FileSystemObject是一个 Windows DLL,在 Mac 上不可用。对于 Mac,您将需要完全不同。
标签: excel operating-system vba