![]() |
#1
|
|||
|
|||
![]()
:!: 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. Code:
Dim Doc As Document Set Doc = OpenDocument("c:\!MCP\Template1a.cdr") Here's my text replacer function, it works on the active document, it takes two args NewText (self evident) and the field/object name. Code:
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 Thanks in Advance (TIA) -wbochar (wolfgang) |
#2
|
||||
|
||||
![]()
Wolfgang,
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: Code:
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 this helps |
#3
|
|||
|
|||
![]()
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.
--wolf |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
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 |