OberonPlace.com Forums  

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

Thread Tools Search this Thread Display Modes
Old 19-03-2003, 09:18
Posts: n/a
Default Active document issues..

:!: I have a CDR11 document that has my vba code embeded in it (Document A). Document A loads another document Document B and replaces text and graphics based on information from a SQL server DB.

Things open/load/pull from DB fine, but I can't seem to make Document B the active document. If I tell CDR11 to scan through the active document's text shapes and replace a named text object with wahetever it will not work on Document B, if I create a duplicate object in Document A it works.

Dim Doc As Document
Set Doc = OpenDocument("c:\!MCP\Template1a.cdr")
If the above code is executed, a new document loads into CDR11. How do I force it to be the active document/page?

Here's my text replacer function, it works on the active document, it takes two args NewText (self evident) and the field/object name.

Private Function TextReplacer(NewText As String, ObjectIDx As String)
        Dim s As Shape
        For Each s In ActivePage.FindShapes(Name:=ObjectIDx, Type:=cdrTextShape)
        s.Text.Contents = NewText
       ' Log the text change
       Print #1, (("Text Replacer ------->" & ObjectIDx & " :" & NewText))
    Next s
End Function
If anyone can help, that would be much appreciated; and to add insult to injury.. What is the procedure for switching pages in the active docuemnt?

Thanks in Advance (TIA)

-wbochar (wolfgang)
Reply With Quote
Old 19-03-2003, 13:33
Alex's Avatar
Alex Alex is offline
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Active document issues..


There are a couple suggestions I have for you:

1. Put your VBA code in a GMS file (separate project), not a document. Thus, it will be more independent of document context. This is just a suggestion, not requirement, so you don't have to do it

2. The mistake you made was to use ActivePage directly in For Each s In ActivePage.FindShapes(...). Note that there is ActivePage property on both Application and Document objects. If your macro is in a GMS module, just using ActivePage means "Application.ActivePage", however if your macro is in a Document, then that document's properties are also global and they take precedence over those of application, and just using ActivePage means "Document.ActivePage". Just to fix your existing code, simply use the following:

For Each s In ActiveDocument.ActivePage.FindShapes(...)

This should take care of it.

3. When you create a new document, get the reference to it and then use it whenever you do something to that document. Don't rely on it being the active document. That's the safest approach:

Dim Doc As Document
Set Doc = OpenDocument(...)
TextReplacer Doc, "NewText", "ObjectName"

Private Function TextReplacer(Doc As Document, NewText As ...)
    For Each s In Doc.ActivePage.FindShapes(...)
End Function
I hope you've got the idea from my very cryptic code above

I hope this helps
Reply With Quote
Old 19-03-2003, 15:15
Posts: n/a
Default Thanks! That helps quite a bit.

I had a feeling that that was where things were going wacky. Much appreciated -- thanks for taking the time to be available for questions and maintaining such a great resource.

Reply With Quote

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
Creating new document problems ddonnahoe Code Critique 2 20-11-2004 17:11
New document creation problem ddonnahoe CorelDRAW/Corel DESIGNER VBA 2 20-11-2004 00:26
Document not open... ddonnahoe CorelDRAW/Corel DESIGNER VBA 4 29-10-2004 14:13
Corel Draw 9 Active Document korner CorelDRAW/Corel DESIGNER VBA 2 17-04-2004 01:46
Condition #1002 -Listman- 0737 (Wierd memory leaks issues) wbochar CorelDRAW/Corel DESIGNER VBA 6 15-05-2003 16:48

All times are GMT -5. The time now is 11:30.

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