[求助]如何得到某一文件的路径?
如何得到某一文件的路径?我用VBA编程,想调用某一EXCEL文件,但我只知道文件的名称,不能完全确定这一文件的存储路径,请高手指教如何通过编程获得该文件的路径,以便能对该文件进行操作.谢谢! 我只知道文件的名称,不能完全确定这一文件的存储路径?不明白。如果你指该文件在搜索路径内,调用LISP的findfile或用Windows API函数搜索所有路径。 <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt"><FONT face="Times New Roman">请高手指点一下GetFullPathName函数的用法:</FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt"><FONT face="Times New Roman"></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt"><FONT face="Times New Roman"></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt"><FONT face="Times New Roman">Private Declare Function GetFullPathName& Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, lpFilePart As Long) <BR>Private Sub Command3_Click() <BR> Dim filename As String <BR> Dim filelength As Long <BR> Dim fullname As String <BR> Dim addres As string<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt"><FONT face="Times New Roman">dim dwgname as string <BR> filename = "jxj1.txt" <BR> filelength = 50 <BR> dwgname=GetFullPathName(filename, filelength, fullname, addres) <BR> Debug.Print fullname <BR>End Sub </FONT><BR style="mso-special-character: line-break"><BR style="mso-special-character: line-break">以上语句不能得到fullname的值,请指出正确用法,谢谢! Private Declare Function GetFullPathName Lib "kernel32.dll" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long
Private Sub Command3_Click()<BR> Dim FileName As String<BR> Dim Buffer As String<BR> Dim numChar As Long<BR> FileName = "jxj1.txt"<BR> Buffer = Space(255)<BR> numChar = GetFullPathName(FileName, 255, Buffer, "")<BR> Buffer = Left(Buffer, numChar)<BR> Debug.Print Buffer<BR>End Sub
上面的api函数不能符合你的意图,它只是将当前路径与指定的文件名合并成文件全名,甚至不验证文件的存在与否。
页:
[1]