VBA中获取文件名的方法
在用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还有其它的法子获得文件路径。
1 2 3 4 5 6 7 8 9 10 | Private Function OpenDialog() As String Dim sFile As String Dim n As Integer '获取路径 sFile = Application.GetOpenFilename("MS excel (*.xls), *.xls") '获取文件title的长度 n = Len(sFile) - InStrRev(sFile, "\") '获得文件title tt = Right(sFile, n) End Function |


保留部分权利
One Comment to “VBA中获取文件名的方法”