Hi,
I'm trying to modify a Corel Drawing programatically using VB.net rather than VBA. I don't seem to be able to do simple things such as FindShape. I've added the CorelDRAW reference library but to no avail... Here's an example of what I want to do:
Dim S as ShapeDim TextToInsert As String
TextToInsert = “New Text”
Set S = ActiveLayer.Shapes.FindShape("SignatureEnglish") ‘should finds your objects named SignatureEnglish – this is case sensitive
If S Is Nothing Then GoTo Ending: ‘if it doesn’t find the shape, go to endEnd if
If Not S Is Nothing And S.Type = cdrTextShape Then ‘if S is anything AND it’s a cdrTextShape object…S.Text.Story = TextToInsert ‘inserts the text in your string variable…
End If
Ending:
Can someone help with this please? Or tell me what's going on in VB.net vs. VBA?
Thanks!
Vibeke
Dim s As Shape
For Each s In ActivePage.ShapesIf s.Name = "signatureenglish" Thens.Name = "foundit"End IfIf s.Type = cdrTextShape Thens.Text.Story = "New Text"End IfNext s
Thank you Michael for your response. I'm still not able to make it work though.
The first line I've changed to: Dim s As CorelDRAW.Shape
The second line "ActivePage" is underlined with the following comment: "Name 'ActivePage' is not declared". I seem to be stuck here. I'm new to this so bear with me please :-).
Thanks Again
Try to declare a Shell at first like a "Sub-" or a "Function-"Command, for example:
Sub YourDesiredSubName()
Dim s As ShapeFor Each s In ActivePage.ShapesIf s.Name = "signatureenglish" Thens.Name = "foundit"End IfIf s.Type = cdrTextShape Thens.Text.Story = "New Text"End IfNext s
End Sub
I still have the same problem... "Name 'ActivePage' is not declared". Help?
Dim s As CorelDRAW.Shape
For Each s In CorelDRAW.ActivePage.ShapesIf s.Name = "signatureenglish" Thens.Name = "foundit"End IfIf s.Type = cdrTextShape Thens.Text.Story = "New Text"End IfNext s
I still can't get it to work, it now says: "'ActivePage' is not a member of 'CorelDRAW'"
thanks
I have some doubt, that the object library of CorelDraw is really referenced.
Did you saved the macro after you have referenced the Draw Object library? That's important, cause otherwise the reference get lost.
Pick it again in the Reference List under the .COM-Tab, declare a reference object with
"Dim drwApp As CorelDRAW.Application
Public Sub Macro()
...
and save the macro. The "Public" Command makes it available for other Projects.
Still the same problem, I've saved, rebuilt, etc...
You have declared the reference "Dim Draw As CorelDRAW.Application" in the Public Class, that's right. But then you should use the reference!
Dim s As Draw.Shape
For Each s In Draw.ActivePage.Shapes
The reference points directly to the Corel Draw Application, so you can use it with all instances like ActivePage, Shape etc. And it is globally accessable (through the "Public" Introduction): this is called "Early Binding". It is good enough in this case. Of course you have to open the Draw document first, which you want to change, when you run that macro. Otherwise you must script an OLE Automation Object with an Object Model... But at first we'll have to see if it works!
Thanks so much for your help! Unfortunately I still can't get it to work! See jpg.
Hm. Seems like the shape object "s" don't "survive" in the routine. I've tried this piece of code to declare a cleaner Automation Object, but didn't have the time to compile it externally yet. You'll need the reference to the "Corel Draw Object Library"(for the Shape) and " Microsoft ActiveX Data Objects Library 2.8"(For the CreateObject). It seems to work till "Set s...":
Sub Signature()Dim Template As StringDim Draw As ObjectDim s As Shape /Edited, try "Dim s As Variant" instead!!!Template = "C:\Test.cdr"Set Draw = CreateObject("CorelDRAW.Application")Draw.Application.Visible = TrueDraw.OpenDocument (Template)Set s = ActivePage.FindShape("SignatureEnglish", cdrTextShape)s.Text.Story = "New Text"ActiveDocument.SaveAs "C:\Test.cdr"Draw.Application.QuitSet Draw = NothingEnd Sub