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 08-08-2005, 12:39
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default Global Variables

In CD12, I have a macro that has Module code that cycles through each page of the active document and shows a form for each page allowing the user to input a file name for each page. The Form code then exports a JPG and AI of the page with the document name that the user inputs. I want to add an Integer variable that will be readable in both the Module and Form codes.

For example...
Code:
Option Explicit
Dim pn As Integer

Sub JPGfromPage()
    Dim Msg As String
    Dim q As Integer
    On Error GoTo 10

    Dim p As Page
    pn = 1
    For Each p In ActiveDocument.Pages
        p.Activate
        frmJPGfromCurrent.Show vbModal
        pn = pn + 1
    Next p
    Exit Sub
10
    For q = 1 To 1000
      Beep
   Next
   Msg = "Error #" & Str(Err.Number) & " was generated by the module." & Chr(13) & Err.Description _
    & Chr(13) & Chr(13) & "You Need to have an open document" & Chr(13) & "with at least 1 exportable object."
    MsgBox Msg, , "Operation Not Possible", Err.HelpFile, Err.HelpContext

End Sub
I then want to pass this "pn" variable to the Form code as follows...
Code:
Option Explicit
Sub cmdGo_Click()
    Me.Hide
    Dim JF As ExportFilter
    Dim d1 As Document
    Set JF = Nothing
    
    
    Set d1 = ActiveDocument
    Dim sx As Double, sy As Double
        ActivePage.Shapes.All.GetSize sx, sy
        Set JF = d1.ExportBitmap("c:\Documents and Settings\Artist\Desktop\" & txbFile.Text & _
        ".jpg", cdrJPEG, cdrCurrentPage, cdrRGBColorImage, sx * 400 / sy, 400, 72, 72)
    
    With JF
        .Compression = 0
        .Optimized = True
        .Smoothing = 0
        .SubFormat = 1
        .Progressive = False
        .Finish
    End With
    Set JF = Nothing
    
        Set JF = d1.ExportEx("c:\Documents and Settings\Artist\Desktop\" & txbFile.Text & _
        ".ai", cdrAI, cdrCurrentPage)
        
    With JF
        .ConvertSpotColors = False
        .IncludePreview = False
        .IncludePlacedImages = False
        .Platform = 1
        .SimulateFills = False
        .SimulateOutlines = False
        .TextAsCurves = True
        .UseColorProfile = False
        .Version = 0
        .Finish
    End With
    Set JF = Nothing


    Unload Me
End Sub

Sub UserForm_Initialize()
    txbFile.Text = ActiveDocument.Name & "-" & pn
    ActiveWindow.ActiveView.ToFitAllObjects
End Sub
Private Sub cmdCancel_Click()
    Unload Me
End Sub
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 08-08-2005, 13:39
petig
Guest
 
Posts: n/a
Default

Simpli use the Public statement insteadof Dim at module level.

"Variables declared using the Public statement are available to all procedures in all modules in all applications unless Option Private Module is in effect; in which case, the variables are public only within theproject in which they reside."
Reply With Quote
  #3  
Old 08-08-2005, 14:59
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Yes, to put petig's advice to actual code:

Code:
Option Explicit
Public pn As Integer
....
Reply With Quote
  #4  
Old 08-08-2005, 16:10
petig
Guest
 
Posts: n/a
Default

Be carefull, the ActiveDocument.Name is not so successful naming the exported files if you plan to use it with more docs: »The Name property returns or sets the name of the VBA object for the current document. In CorelDRAW, this name is always "Thisdocument" unless changed by the user.« Use the FileName property instead. You may use the ActivePage.Name or ActivePage.Index also to name unicaly the export file. In this case you don't need a counter (pn). Something like this:

txbFile.Text = Left(ActiveDocument.FileName,Len(ActiveDocument.FileName)-4) & "-" & Format(ActivePage.Index,"00")

And, if it doesn't hurt that I talk and talk, that Errorhandling is not necessary in your code. I suggest, just use a simplier way to check, if your process is doable or not. In this case it's so easy: just check if the active page has any shape on it. Also not necessary to initialize and unload the form at every pages, good enough only hide that to make the whole page visible, and, when the user cliks, pop up again for input -- terminate only one time, when all the desired pages exported.
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
Reset All Variables ddonnahoe Code Critique 0 06-01-2005 07:16
Find objects by properties Webster CorelDRAW/Corel DESIGNER VBA 8 01-12-2004 18:51
Global color change ddonnahoe CorelDRAW/Corel DESIGNER VBA 8 18-05-2004 11:08
Batch script "meta" variables dleigh Corel Photo-Paint CS 0 17-02-2003 08:00


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


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