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 02-05-2010, 09:55
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 431
Default X5 Watch For Specific Action

Hello, is there any way to get vba to watch for a specific user action? I like every page in my document to have the same layer structure. With X5 when I click the plus by the page numbers to get a new page I end up with a new page containing Layer 1 only. I'd like to have a macro that watches out for when the new page button is used and then renames the layers according to the structure I have for page 1. That bit I can do, and I know I can create a button to call the macro or use a shortcut but I can imagine there are times when I will just click on the new page button without thinking. So I want a macro that runs in the background and auto corrects the layer structure. Is it possible?

Thanks,

Chris
Reply With Quote
  #2  
Old 02-05-2010, 12:35
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
 
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811
Default

Hi.
If you add:

Code:
Private WithEvents CurDoc As Document
to the top of your thisMacroStorage module you can use the current document event pageCreate.

Also see this.

-John
Reply With Quote
  #3  
Old 02-05-2010, 13:54
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
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 WithEvents

Agreed WithEvents is the way to go. Here is a quick example of what you want. It will not delete extra layers in the page, but it will create all layers in the first page to the newly created page.

Code:
Option Explicit
Private WithEvents CurDoc As Document

Private Sub GlobalMacroStorage_WindowActivate(ByVal Doc As Document, ByVal Window As Window)
    Set CurDoc = Doc
End Sub

Private Sub GlobalMacroStorage_WindowDeactivate(ByVal Doc As Document, ByVal Window As Window)
    Set CurDoc = Nothing
End Sub

Private Sub CurDoc_PageCreate(ByVal Page As Page)
    Dim pgFirst As Page, lr As Layer
    
    Set pgFirst = ActiveDocument.Pages.First
    
    For Each lr In pgFirst.Layers
        FindLayer Page, lr.Name
    Next lr
End Sub

Private Sub FindLayer(ByVal pg As Page, ByVal strName As String)
    Dim LayerFound As Layer
    Dim lr As Layer

    Set LayerFound = Nothing
    
    For Each lr In pg.Layers
        If StrComp(lr.Name, strName, vbTextCompare) = 0 Then
            Set LayerFound = lr
            Exit For
        End If
    Next lr

    If LayerFound Is Nothing Then
        Set LayerFound = pg.CreateLayer(strName)
    End If
End Sub
-Shelby
Reply With Quote
  #4  
Old 02-05-2010, 17:57
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 431
Default

Thanks, John and Shelby, that's very useful. Is there anyway to do something similar for creating new documents. The thought has occurred that I could set up my basic layers when a new document is created automatically.

Chris
Reply With Quote
  #5  
Old 02-05-2010, 18:10
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
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 GlobalMacroSotrage

The new document trigger is in the GlobalMacroStorage. Like this:

Code:
Private Sub GlobalMacroStorage_DocumentNew(ByVal Doc As Document, ByVal FromTemplate As Boolean, ByVal Template As String, ByVal IncludeGraphics As Boolean)

End Sub
Here you can capture events like before or after save. New and close documents, all sorts of good stuff.

-Shelby
Reply With Quote
  #6  
Old 02-05-2010, 19:01
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 431
Default

Thanks, Shelby, now I can start cooking!

Chris
Reply With Quote
  #7  
Old 02-05-2010, 19:38
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 431
Default

I've had another thought - is there any way to watch for the creation of a new non-master layer? That way I could keep all my layers in sync automatically. I don't like or need individual layers per page!

Chris
Reply With Quote
  #8  
Old 02-05-2010, 19:54
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
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 Layers

I have not tested this, but something like this should work:
Code:
Private Sub CurDoc_LayerCreate(ByVal Layer As Layer)
    If Not Layer.Master Then
        'Do somthing here
    End If
End Sub
Best of luck,

-Shelby
Reply With Quote
  #9  
Old 02-05-2010, 20:56
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 431
Default

Thanks, Shelby, it works. Incidentally, does X5 have any method for making a new master layer? Currently I use:

Code:
Dim lr0 As Layer
    
    Set lr0 = ActivePage.CreateLayer("NAME")
    lr0.Master = True
Any method to do it in one step?

Cheers,

Chris
Reply With Quote
  #10  
Old 02-05-2010, 21:22
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
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 MasterPage

Again this is not tested, but I think it should work to just create the layer on the MasterPage, therefore it would be a MasterLayer.

Code:
Set lr0 = ActiveDocument.MasterPage.CreateLayer("NAME")
-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
How to select a word at specific tab position aakkaarr CorelDRAW/Corel DESIGNER VBA 4 28-12-2009 14:43
Align to Specific Layer ProofingGuy CorelDRAW/Corel DESIGNER VBA 6 11-06-2008 17:11
Identifying specific lines of paragraph text knowbodynow CorelDRAW/Corel DESIGNER VBA 3 06-12-2007 02:58
auto naming exported file to specific path vindaa Macros/Add-ons 0 18-08-2006 16:50
Menu that open a specific page in the WebConnector vida CorelDRAW/Corel DESIGNER VBA 5 15-03-2005 12:48


All times are GMT -5. The time now is 17:14.


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