VBA中获取文件名的方法
March 2nd, 2008 | by 味小精 |在用excel做文件导入时发现,一旦使用Commond Dialogs 就会出错
“The control could not be created because it is not properly licensed”
原因是,Commond Dialogs are not licensed to be used in Excel。经过搜索发现,其实VBA还有其它的法子获得文件路径。
[code:vb]
Private Function OpenDialog() As String
Dim sFile As String
Dim n As Integer
sFile = Application.GetOpenFilename(”MS excel (*.xls), *.xls”) ‘获取路径
n = Len(sFile) - InStrRev(sFile, “\”) ‘获取文件title的长度
tt = Right(sFile, n) ‘获得文件title
End Function
[/code]

