OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 19-02-2009, 08:47
mateushenrico
Guest
 
Posts: n/a
Question Checking folders and subfolders

Hi there!

I set the code below to publish pdf:


Sub MakePDF()

DirOpenFile = ActiveDocument.FilePath
Directory = Dir$(DirOpenFile)

Do While Len(Directory) <> 0

Set File = OpenDocument(Directory)
NameWithoutCdr = Replace(Directory, ".cdr", ".pdf")

File.PublishToPDF (DirOpenFile & NameWithoutCdr)
File.Close
Counting = Counting + 1
Directory = Dir$

Loop

End Sub


Could anyone tell me what should I do to make the macro search also into existing subfolders (if they exist or not)?
Reply With Quote
  #2  
Old 21-02-2009, 00:31
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Checking subfolders

You can find Alex's original code here: Finding a File in Sub Folders I have combined the changes in the thread to the following code:
Code:
Private Sub EnumSubFolders(ByVal SrcFolder As String, ByVal Folders As Collection)
    Dim f As String
    
    f = Dir(SrcFolder & "\*.*", vbDirectory)
    
    While f <> ""
        If f <> "." And f <> ".." And (GetAttr(SrcFolder & "\" & f) And vbDirectory) <> 0 Then
            Folders.add SrcFolder & "\" & f
        End If
        f = Dir()
    Wend
End Sub

Private Sub ProcessFolder(ByVal SrcFolder As String)
    Dim f As String, sFolder As Variant
    Dim Folders As New Collection
    Dim n As Long
    
    ' Create a list of folders and subfolders
    EnumSubFolders SrcFolder, Folders
    
    n = 1
    While n <= Folders.Count
        EnumSubFolders Folders(n), Folders
        n = n + 1
    Wend
    
    ' Process the CDR files in each of the folders found
    For Each sFolder In Folders
        f = Dir(sFolder & "\*.cdr")
    
        While f <> ""
            ProcessFile sFolder & "\" & f
            f = Dir()
        Wend
    Next sFolder
End Sub

Private Sub ProcessFile(ByVal sFile As String)
    ' Do your file processing here
End Sub
And as Alex's says here is how you can use it.
Code:
Public Sub Test()
    ProcessFolder "D:\Temp"
End Sub
This will call ProcessFile subroutine for every CDR file found in D:\Temp or any of its subfolders. Hope that gets you pointed in the correct direction.

-Shelby
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
folders in International Languages jemmyell CorelDRAW/Corel DESIGNER VBA 2 03-02-2009 17:01
Checking fill type knowbodynow CorelDRAW/Corel DESIGNER VBA 2 08-03-2006 02:18
Checking for shape intersection Todor CorelDRAW/Corel DESIGNER VBA 3 03-07-2005 10:48
Finding a File in Sub Folders shelbym CorelDRAW/Corel DESIGNER VBA 10 10-05-2004 08:02
Checking if a file exists before importing Rick Randall CorelDRAW/Corel DESIGNER VBA 1 01-03-2004 10:33


All times are GMT -5. The time now is 06:05.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com