方法二:使用MAX函数(请在VBE/工具/引用中,勾选对于MICROSOFT EXCEL 10.0 OBJECT LIBRARY 的引用) '* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-4-20 07:03:16
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------Option Explicit
'运行此代码前必须检查VBE/工具/引用:勾选对于Microsoft Excel 10.0(视版本不同) Object Library
Sub Example()
Dim ADoc As String, FileList As Integer, MyArray() As Integer, aArray As Variant
Dim i As Integer, ExlApp As Excel.Application
On Error Resume Next '忽略错误
ChDrive "E" '设置当前驱动器盘符请在此处更改盘符
ChDir "E:\Test" '进入指定目录'请在此处更改文件夹位置
ADoc = Dir("A*.doc") '定义一个以A开头的任意DOC文件的string变量
Do While ADoc <> "" '非空
FileList = VBA.Mid(ADoc, 2, Len(ADoc) - 5) * 1 '文件名序号为第二个字符开始到最后第四个字符(.DOC)结束
ReDim Preserve MyArray(i) '加上Preserve是保留原来的数组中的数据
MyArray(i) = FileList
i = i + 1
ADoc = Dir()
Loop
' For Each aArray In MyArray
' MsgBox aArray
' Next
Set ExlApp = New Excel.Application
With ExlApp
MsgBox "指定文件夹中A为首的最大序号文件为A" & .WorksheetFunction.Max(MyArray) & ".Doc", vbOKOnly + vbInformation
.Quit
End With
Set ExlApp = Nothing
End Sub
'---------------------- |