注册 登录
Office中国论坛/Access中国论坛 返回首页

tanhong的个人空间 http://www.office-cn.net/?49992 [收藏] [复制] [分享] [RSS]

日志

返回长文件名的短文件名函数

已有 1033 次阅读2009-1-30 22:15 |个人分类:VBA代码实例|

如我们在使用REGSVR32.exe注册控件时,如果这个控件的路径中有空格或者文件名太长,就会注册不成功,因为REGSVR32.exe不支持长文件名,下面的函数就是解决这样的类似的问题:
' 例如
' ? getShortPath("C:\Documents and Settings\Administrator\桌面\")
' C:\DOCUME~1\ADMINI~1\桌面\
'------------------------------------------------------------
Option Compare Database
Option Explicit
Private Declare Function GetShortPathName32 Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Public Function getShortPath(ByVal strFullPath As String) As String
    Dim strShortPath As String
    strShortPath = Space(256)
    GetShortPathName32 strFullPath, strShortPath, 256
    strShortPath = Left(strShortPath, InStr(strShortPath, Chr(0)) - 1)
    getShortPath = strShortPath
End Function

发表评论 评论 (1 个评论)

回复 tmtony 2009-1-31 00:05
不错, 学习了

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-3 11:01 , Processed in 0.061120 second(s), 18 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部