• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Search in folder and subfolders

Fila

New Member
Hello can you help me please with edit this code. I would like modify the code so that could search in subfolders. Thank you

Public Function PrintThisDoc(formname As Long, FileName As String)
On Error Resume Next
Dim x As Long
x = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
End Function
_______________________________________________________
Public Function ZkontrolovatAVytiskoutSoubor() As Boolean
Dim printThis
Dim strDir As String
Dim strFile As String
strDir = "W:\Etikety\Štítky\Krabice\Testy"
strFile = Range("C2").Value & ".lbe"
If Not FileExists(strDir & "\" & strFile) Then
MsgBox "soubor neexistuje!"
ZkontrolovatAVytiskoutSoubor = False
Else
printThis = PrintThisDoc(0, strDir & "\" & strFile)
ZkontrolovatAVytiskoutSoubor = True
End If
End Function

Private Function FileExists(fname) As Boolean
' Returns TRUE if the file exists
Dim x As String
x = Dir(fname)
If x <> "" Then FileExists = True _
Else FileExists = False
End Function
 
I got this code from somewhere. Try editing as per your requirement.
Code:
Sub Retrieve_File_listing()
    Worksheets(1).Cells(2, 1).Activate
    Call Enlist_Directories(ThisWorkbook.Path & "\", 1)
End Sub

Public Sub Enlist_Directories(strPath As String, lngSheet As Long)
    Dim strFldrList() As String
    Dim lngArrayMax, x As Long
    lngArrayMax = 0
    strfn = Dir(strPath & "*.*", 23)
    While strfn <> ""
        If strfn <> "." And strfn <> ".." Then
            If (GetAttr(strPath & strfn) And vbDirectory) = vbDirectory Then
                lngArrayMax = lngArrayMax + 1
                ReDim Preserve strFldrList(lngArrayMax)
                strFldrList(lngArrayMax) = strPath & strfn & "\"
            Else
                ActiveCell.Value = strPath & strfn
                ActiveCell.Offset(0, 1).Value = strfn
                Worksheets(lngSheet).Cells(ActiveCell.Row + 1, 1).Activate
            End If
        End If
    strfn = Dir()
    Wend
    If lngArrayMax <> 0 Then
        For x = 1 To lngArrayMax
            Call Enlist_Directories(strFldrList(x), lngSheet)
        Next
    End If
End Sub
 
Thank you, but I would like implemate to this code, i dont know how.

Code:
  Public Function PrintThisDoc(formname As Long, FileName As String)
On Error Resume Next
Dim x As Long
x = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
End Function
_______________________________________________________
Public Function ZkontrolovatAVytiskoutSoubor() As Boolean
Dim printThis
Dim strDir As String
Dim strFile As String
strDir = "W:\Etikety\Štítky\Krabice\Testy"
strFile = Range("C2").Value & ".lbe"
If Not FileExists(strDir & "\" & strFile) Then
MsgBox "soubor neexistuje!"
ZkontrolovatAVytiskoutSoubor = False
Else
printThis = PrintThisDoc(0, strDir & "\" & strFile)
ZkontrolovatAVytiskoutSoubor = True
End If
End Function

Private Function FileExists(fname) As Boolean
' Returns TRUE if the file exists
Dim x As String
x = Dir(fname)
If x <> "" Then FileExists = True _
Else FileExists = False
End Function
 
Back
Top