当前位置:首页 > VBA文件及文件夹操作
If mySh Is Nothing Then '新建一个工作簿
iSheetsInNew = Application.SheetsInNewWorkbook Application.SheetsInNewWorkbook = 1 Set wb = Application.Workbooks.Add
Application.SheetsInNewWorkbook = iSheetsInNew Set sh = wb.Sheets(1) Else
Set mySh = sh End If With sh
Range(.Cells(1, 1), .Cells(UBound(varData, 1) + 1, UBound(varData, 2) + 1)) = varData
.UsedRange.Columns.AutoFit End With Set sh = Nothing Set wb = Nothing End Sub
2.关闭VBA编辑器,回到Excel工作表中,按Alt+F8,打开“宏”对话框,选择“GetFileList”,单击“运行”按钮。
7.VBA中如何取文件的最后修改时间?
已经解决了,新的代码
--------------------------------------------- Sub searchfiles()
With Application.FileSearch .NewSearch .LookIn = \:\\ttt\.Filename = \.SearchSubFolders = True .FileType = msoFileTypeAllFiles If .Execute() > 0 Then For i = 1 To .FoundFiles.Count
Worksheets(\Dim fs, f, s
Set fs = CreateObject(\Set f = fs.GetFile(.FoundFiles(i)) s = \: \Worksheets(\Set f = Nothing Set fs = Nothing Next i Else
MsgBox \End If End With End Sub
8.VBA代码调用浏览文件夹对话框的几种方法
2009-05-25 15:24
1、使用API方法 '【类型声明】
Private Type BROWSEINFO hWndOwner As Long pIDLRoot As Long pszDisplayName As Long lpszTitle As Long ulFlags As Long lpfnCallback As Long lParam As Long iImage As Long End Type '【API声明】
Private Declare Function SHGetPathFromIDList Lib \Alias \ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib \
Alias \Private Declare Function lstrcat Lib \Alias \ByVal lpString2 As String) As Long
Private Declare Function OleInitialize Lib \(lp As Any) As Long
Private Declare Sub OleUninitialize Lib \Private Const BIF_USENEWUI = &H40
Private Const MAX_PATH = 260 '【自定义函数】
Public Function GetFolder_API(sTitle As String, Optional vFlags As Variant) As String
Dim lpIDList As Long Dim sBuffer As String Dim BInfo As BROWSEINFO
If IsMissing(vFlags) Then vFlags = BIF_USENEWUI Call OleInitialize(ByVal 0&) With BInfo
.lpszTitle = lstrcat(sTitle, \.ulFlags = vFlags End With
lpIDList = SHBrowseForFolder(BInfo) If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1) If sBuffer <> \End If
Call OleUninitialize End Function '【使用方法】 Sub Test()
MsgBox GetFolder_API(\选择文件夹\
共分享92篇相关文档