Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for a file with the same reference - VBA.. 1

Status
Not open for further replies.

basepointdesignz

Programmer
Jul 23, 2002
566
GB
Hi again, again!!

For every drawing we do @ my work, we have a corresponding Excel worksheet (an order) that goes with it. I'm trying to write a module that runs from AutoCAD and will search a particular folder for the excel file that matches the customer reference, then it opens it. If one does not exist, it simply opens a new file from the template..

What I'm unsure on is the correct function/method for searching for the file and querying what it comes up with.
Does the FindFile function work well (in VBA)? I can extract the customer name and job number from the drawing name and the excel file but I just need to know how to start the search..

Thanks in advance..

Renegade..

P.S No more questions - I promise!!
 
This may get you started....

Function GetFileListByExtension(ByVal sDirPath As String, _
ByVal sExt As String) As Variant
'------------------------------------------------------------------------------
'GetFileListByExtension:
'------------------------------------------------------------------------------
Dim sTempName As String
Dim lFileCnt As Long
Dim vFiles() As Variant

If GetAttr(sDirPath) = vbDirectory Then
sTempName = Dir(sDirPath, vbDirectory)
Do Until Len(sTempName) = 0
' Exclude ".", "..".
If (sTempName <> &quot;.&quot;) And (sTempName <> &quot;..&quot;) Then
' Make sure we do not have a sub-directory name.
If (GetAttr(sDirPath & sTempName) _
And vbDirectory) <> vbDirectory Then
' Increase the size of the array
' to accommodate the found filename
' and add the filename to the array.
If Right$(sTempName, 4) = sExt Then
ReDim Preserve vFiles(lFileCnt)
vFiles(lFileCnt) = sTempName
lFileCnt = lFileCnt + 1
End If
End If
End If
' Use the Dir function to find the next filename.
sTempName = Dir()
Loop
' Return the array of found files.
If lFileCnt <> 0 Then
GetFileListByExtension = vFiles
End If
End If
End Function
 
Thanks again Borgunit,

It's just what I need - All need to do now is read it and try to make sense of what it all means..

Cheers,

Renegade..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top