TheSwamp

Code Red => VB(A) => Topic started by: Amsterdammed on June 03, 2005, 12:56:55 PM

Title: findfile without dialogbox
Post by: Amsterdammed on June 03, 2005, 12:56:55 PM
Does in VBA something like findfile in Lisp exist or does it always open the dialog? :?:
Title: findfile without dialogbox
Post by: Keith™ on June 03, 2005, 01:26:31 PM
You can use something like this:

Code: [Select]

Dim filenamewithpath As String
Dim filename As String
filenamewithpath = "C:\Program Files\ACAD2006\SomelispFile.lsp"
filename = Dir(filenamewithpath)
If filename = "" Then
 MsgBox "File does not exist"
End If
Title: findfile without dialogbox
Post by: Amsterdammed on June 03, 2005, 02:06:33 PM
I understand this.

My Problem is that I work for company with offices in different towns, every office is run by different IT clowns with different working methodes. So I don't know the locations where my code must find a certain file. In lisp i would let it search with findfile  for my mnl file and than I know the location where my stuff is parked.
Title: findfile without dialogbox
Post by: MP on June 03, 2005, 04:06:25 PM
I think what you are looking for is an implementation of FindFirstFile (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/findfirstfile.asp) and FindNextFile (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/findnextfile.asp) API calls that will work in VBA. Go to this  (http://www.vbnet.mvps.org/index.html?http://www.vbnet.mvps.org/search/main/index.html)page, type findfirst into the Search for box and then press [Search VBNet].

Example1 (http://www.vbnet.mvps.org/code/fileapi/foldercontent.htm); example2 (http://www.vbnet.mvps.org/code/fileapi/recursive.htm).

/perhaps
Title: findfile without dialogbox
Post by: Amsterdammed on June 18, 2005, 09:54:11 AM
I found this on the web, posted by Bob Wahr in 2003

Code: [Select]

Private Function FindFile(strFile As String)
Dim strSupPth As String
Dim varPaths As Variant
Dim intCnt As Integer
Dim strFnd As String
Dim strTest As String
Dim strDwgDir As String

strSupPth = ThisDrawing.GetVariable("acadprefix")
strDwgDir = ThisDrawing.GetVariable("dwgprefix")
strTest = Dir(CurDir & "\" & strFile, 31)
If strTest <> "" Then
strFnd = CurDir & "\" & strTest
Else
strTest = Dir(strDwgDir & "\" & strFile, 31)
If strTest <> "" Then
strFnd = strDwgDir & "\" & strFile
Else
If strSupPth <> "" Then
varPaths = Split(strSupPth, ";", -1, vbTextCompare)
For intCnt = 0 To UBound(varPaths)
strTest = Dir(varPaths(intCnt) & "\" & strFile, 31)
If strTest <> "" Then
strFnd = varPaths(intCnt) & "\" & strFile
Exit For
End If
Next intCnt
End If
End If
End If

FindFile = strFnd

End Function