Hello. Corel Community!
I'm using CorelDRAW 2019.
I'am newbie in VBA. I need to loop a simple action for all files in folder.I have a folder with .SVG files, I need to open one, crop it, save it and etc. for each file in folder.
There is the macro for one file crop
Sub Crop()
Dim crop1 As ShapeRange Set crop1 = ActivePage.CustomCommand("Crop", "CropRectArea", 1.125, 4.625, 5.125, 8.625) Dim grp1 As ShapeRange Set grp1 = crop1.UngroupAllEx i = ActiveSelection.Shapes.Count ActiveSelection.Shapes(i).Delete i = ActiveSelection.Shapes.Count ActiveSelection.Shapes(i).Delete Dim sel As Shape Set sel = ActiveDocument.Selection Set sel = grp1.Group sel.CreateSelection
Dim crop1 As ShapeRange
Set crop1 = ActivePage.CustomCommand("Crop", "CropRectArea", 1.125, 4.625, 5.125, 8.625)
Dim grp1 As ShapeRange
Set grp1 = crop1.UngroupAllEx
i = ActiveSelection.Shapes.Count
ActiveSelection.Shapes(i).Delete
Dim sel As Shape
Set sel = ActiveDocument.Selection
Set sel = grp1.Group
sel.CreateSelection
End Sub
I tried to find any information about loop in Corel in Google, but there is many VBA's for Word and Excel, and they don't won't to work in Corel. Or may be I don't have experience. I tried to put my code within the loop, but don't get any result. This one for example
Option Explicit Public Sub test() ProcessFolder "C:\Test"End Sub 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() WendEnd 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 & "\*.svg") While f <> "" ProcessFile sFolder & "\" & f f = Dir() Wend Next sFolderEnd Sub Private Sub ProcessFile(ByVal sFile As String) Dim crop1 As ShapeRange Set crop1 = ActivePage.CustomCommand("Crop", "CropRectArea", 1.125, 4.625, 5.125, 8.625) Dim grp1 As ShapeRange Set grp1 = crop1.UngroupAllEx i = ActiveSelection.Shapes.Count ActiveSelection.Shapes(i).Delete i = ActiveSelection.Shapes.Count ActiveSelection.Shapes(i).Delete Dim sel As Shape Set sel = ActiveDocument.Selection Set sel = grp1.Group sel.CreateSelectionEnd Sub
Option Explicit
Public Sub test() ProcessFolder "C:\Test"End Sub
Public Sub test()
ProcessFolder "C:\Test"
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() WendEnd Sub
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
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 & "\*.svg") While f <> "" ProcessFile sFolder & "\" & f f = Dir() Wend Next sFolderEnd 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
' Process the CDR files in each of the folders found
For Each sFolder In Folders
f = Dir(sFolder & "\*.svg")
ProcessFile sFolder & "\" & f
Next sFolder
Private Sub ProcessFile(ByVal sFile As String) Dim crop1 As ShapeRange Set crop1 = ActivePage.CustomCommand("Crop", "CropRectArea", 1.125, 4.625, 5.125, 8.625) Dim grp1 As ShapeRange Set grp1 = crop1.UngroupAllEx i = ActiveSelection.Shapes.Count ActiveSelection.Shapes(i).Delete i = ActiveSelection.Shapes.Count ActiveSelection.Shapes(i).Delete Dim sel As Shape Set sel = ActiveDocument.Selection Set sel = grp1.Group sel.CreateSelectionEnd Sub
Private Sub ProcessFile(ByVal sFile As String)
Help me please! Thank you!
Could you explain what "Crop" means? What was before crop and what happened after?
Hi! This is action I need to do with one file. Code of this action above, first one.. Below code where I tried to put this code to loop. But I'm noob. Before "crop" need to open SVG file from folder. Crop it. Save it. Close it. Open another SVG, from same folder. Crop it....
i think, you first must import your SVG-file to crop it.
dim s as shape
ActiveLayer.Import "youfile.svg"
set s = ActiveLayer.Shapes.First
s.AddToSelection
Activepage.CustomCommand("Crop ...