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 04-09-2007, 22:39
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default Layers And List Boxs

Hello, this is really a general question about VBA but I haven't been able to find an answer searching online. I'm trying to make a user form that allows the user to select what layers will be used to save objects to a new file. I've used a list box to list the available layers as a list box allows the user to select multiple items. My problem is I don't know how to proceed when the user presses the OK button. How do I access multiple selected items in a list box? The examples online I've seen refer to listboxname.itemsSelected but itemsSelected seems to be part of Microsoft Access and not part of CorelDraw VBA. How do I get at the items selected in the list box?

Thanks,

Chris (Hunt)
Reply With Quote
  #2  
Old 05-09-2007, 10:34
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default Figured it Out

I figured out a way. Below is the clunky code I used. layerlist is the name of the list box.

Chris

Code:
Private Sub cmdOK_Click()

Dim i As Integer, t As Integer, pi As Integer, tdoc As Integer
Dim nam As String, oFilder As String, oFilename As String

t = layerlist.ListCount
oFolder = "S:\Image Library\Clipart\ZZ Flashcards"

tdoc = ActiveDocument.Pages.Count
pi = 1

While pi < tdoc + 1

ActiveDocument.Pages(pi).Activate

ActiveDocument.ClearSelection

oFilename = ActivePage.name

i = 0

While i < t

If layerlist.Selected(i) = True Then
nam = layerlist.List(i)
ActivePage.Layers(nam).Shapes.All.AddToSelection
End If

i = i + 1

Wend

i = 0

While i < t

If layerlist.Selected(i) = True Then
nam = layerlist.List(i)
ActiveDocument.MasterPage.Layers(nam).Shapes.All.AddToSelection
End If

i = i + 1

Wend

If ActiveSelection.Shapes.Count > 0 Then

Dim opt As New StructSaveAsOptions
        opt.EmbedVBAProject = False
        opt.Filter = cdrCDR
        opt.IncludeCMXData = True
        opt.Range = cdrSelection
        opt.EmbedICCProfile = False
        opt.ThumbnailSize = cdr10KColorThumbnail
        opt.Version = cdrCurrentVersion
        opt.Overwrite = True

ActiveDocument.SaveAs oFolder & Chr(92) & oFilename & ".cdr", opt

End If

pi = pi + 1

Wend

Unload Me

End Sub
Reply With Quote
  #3  
Old 05-09-2007, 14:07
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,790
Blog Entries: 13
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 Your on a roll...

Great to see that you got it working. Here is a little different version.
Code:
Private Sub cmdOK_Click()
    Dim p As Page
    Dim i As Integer
    Dim doc As Document
    Dim opt As New StructSaveAsOptions
    Dim nam As String, oFolder As String, oFileName As String
    
    Set doc = ActiveDocument
    
    With opt
        .EmbedVBAProject = False
        .Filter = cdrCDR
        .IncludeCMXData = True
        .Range = cdrSelection
        .EmbedICCProfile = False
        .ThumbnailSize = cdr10KColorThumbnail
        .Version = cdrCurrentVersion
        .Overwrite = True
    End With
    
    oFolder = "S:\Image Library\Clipart\ZZ Flashcards"
    
    For Each p In doc.Pages
        p.Activate
        doc.ClearSelection
        oFileName = p.Name
        
        For i = 0 To LayerList.ListCount - 1
            If LayerList.Selected(i) = True Then
                nam = LayerList.List(i)
                p.Layers(nam).Shapes.All.AddToSelection
                doc.MasterPage.Layers(nam).Shapes.All.AddToSelection
            End If
        Next i
        
        If ActiveSelection.Shapes.Count > 0 Then doc.SaveAs oFolder & Chr(92) & oFileName & ".cdr", opt
    Next p
End Sub
-Shelby
Reply With Quote
  #4  
Old 06-09-2007, 07:05
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

Thanks, Shelby. I've replaced my own version with your much more elegant solution.

Chris
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
How controll lot of layers? petig CorelDRAW/Corel DESIGNER VBA 5 28-08-2005 02:35


All times are GMT -5. The time now is 08:07.


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