Hello,
While I've come to a better understanding of manipulating curve shapes, text is still a big hurdle for me. I try pretty hard to figure this stuff out on my own but seriously 50+ debug attempts on what should be a very small and simple (stage within a larger) macro really breaks me down.
What I'm trying to do is select a collection of artistic text fields, add a comma to the end of each one, bring them all together into one field and reverse their order. I will briefly explain a bit better. The comma is enough, no space adding required. The "combine" function of DRAW works fine for bringing them all together into one field, but it puts them in the reverse order of what I need, which makes sense because C1 is created first, then C2 and so on - resulting in C10C9C8 etc. I thought I was on the right track in the Object Browser when I found the InsertAfter "class member", but I got nowhere with the VBA example provided in the (F1) CorelDRAW X7 Macros Help resource. The example at least showed me how to insert specified text at the end of a paragraph text, even though I use artistic text. That much isn't a big deal of course, but the real trouble is I do not understand stuff like "Set s = d..." followed by Set t =s..." and how they interact in this example. This is the VBA help example:
The following VBA example inserts the sentence This will be inserted last. after the paragraph text This is an example.
In my attempts to use this example, one of many troubles was that of course I don't need to create a new document as I'm already working in one, so I managed to do away with that without ruining the Set s = d part, though I've probably forgotten how by now. Then there's the problem that I am dealing with a selection range of Text, so that introduces the "t" aspect. When I try to do stuff like "for each s in sr" or "for each t in sr" (if that is even possible), I can't get it to work.
Here is an image of what I'm trying to achieve at this stage within a larger macro:
All help is appreciated!
Sub Macro4trey86
Dim s As Shape, sr As ShapeRange, ResultStr As String
Set sr = ActiveSelectionRange: If sr.Count = 0 Then Exit Sub 'working with selected text shapes
Set sr = sr.ReverseRange ' inverse order. This string you may remove
ResultStr = ""
For Each s In sr
If ResultStr <> "" Then ResultStr = ResultStr & "," 'adding comma
ResultStr = ResultStr & s.Text.Story.Text ' adding text. If you selected non-text shape then get error
Next s
Set s = Activelayer.CreateArtisicText(1,1, ResultStr) 'creating new shape with result
End Sub
Hey, Shark!
Thanks for looking into this with me. This will help me understand strings better, as that method is new to me. However, I may be doing something wrong, or I may have missed something in my explanation. I'm getting an error on that last line which prevents anything from playing in the macro. Screenshot:
If I understood strings better I may be able to spot the issue, but at this time I do not.
missed "t" in CreateArtisticText
Oh man, I should have caught that! Hah. Sorry I didn't even think to look for typos, didn't cross my mind that it may have been such a simple issue.Thanks so much, this is great.
Every shape I work with (hundreds per day) has a label of this kind "A1,B1,C1", or "A1,A2,A3", or "1,2,3" etc. which I assign to them and type on them. Before learning of VBA's existence, I had to re-type each one, separated by commas, as a title above the the panel of nested shapes with these labels. At least when I found VBA I got it to the point of duplicating the selection range of labels, "combining" them, moving that result to the top center of the panel, then manually would go in and add the commas. But that was still really annoying, especially because when "A1" landed right by "3" for example, i'd get "A13", and many shapes per project ARE "A13", so I always had to check if I need to put the comma before or after the "3" in this example. A "combined" range of labels like this could result in a panel title like "5A132B4B2143C3" and I'd have to carefully place the commas to get "5,A1,3,2,B4,B2,1,4,C,3", and you can see how that is open to error if I misplace a comma, and that is bad because these panels names go into Excel for production and pricing purposes. I know all this info is irrelevant to everyone but me, haha, but I wanted to tell you so that you get an idea of how much you've just helped me
by the way, with the help of CorelDRAW VBA, you can directly access Excel cells, write any information there and then save the .xls file. Excel himself will not even be shown on the screen.
That sounds interesting, shark_. Do you have any further information or resources on how to go about doing that? It relates to another thing I do manually every day. Maybe you have a suggestion for this one too? Here is an image explaining the process. This is a small example of just six text objects. Its usually up between 15-30 and sometimes around half of them have this same issue of not combining into one line due to the space between multiple words, as the image explains for "SEA GLASS". Thus far, all I can figure is to manually get those into one line by removing the Enter/Return keystroke which put them down on that second line. Any ideas?
Sub Text_text()Dim sr As ShapeRange, s As Shape, A$ Set sr = ActiveSelectionRange.Shapes.FindShapes(, cdrTextShape) 'find text only For Each s In sr A = s.Text.Story.Text: A = Replace$(A, vbCr, " ") ' replace EOL to Space s.Text.Story.Text = A NextEnd Sub
trey86 said: Do you have any further information or resources on how to go about doing that?
I wrote a macro for myself that directly writes from CorelDRAW the data I need into the Excel table, for example, the size (width x height) and name of the files I printed. I can write the same macro for you