I'm having trouble finding information on how to control Microsoft Word with CorelDraw macros. I'm trying to create a Macro that can copy text from CorelDraw into Word. Ideally it will paste this text into text boxes while retaining as much formatting as possible.
I'm using X4. The initial part of the script I've written finds text objects in Draw that contain a certain word. All the text within these text objects needs to be copied. The formatting (bold, italics, size, leading) may vary throughout the text range. Retaining the formatting may be complicated but if someone knows a way to copy the text into Word text boxes it will be a good start.
Thanks for any help.
Right now I can get the following code to work from CorelDraw:Sub WordPlay()Dim i As IntegerSet wrdApp = CreateObject("Word.Application")wrdApp.Visible = TrueSet wrdDoc = wrdApp.Documents.Add ' create a new documentWith wrdDocDim Box As ShapeFor i = 1 To 2.Content.InsertAfter "Here is a example test line #" & i.Content.InsertParagraphAfterNext iEnd WithEnd SubDoes anyone know how I can get the sample text into text boxes? Thanks in advance.
I'll take a stab at it. What you'll want to do before hitting your macro would be to copy what text you want into the word text box. Now at the end of your code maybe add
SendKeys "^(v)"
this will only work if your macro opens an instance of word and your cursor ends up where it needs to be before it pastes. Otherwise you may have to add some SendKey options like "{TAB}" etc.
I don't have word so I can't see where the cursor ends up.
Myron
HolyMacro,
There are several ways you could do this. If you selected the line of text you can create a TextBox from the selection like this:
Sub TestBoxwithSelection() If Selection.Type = wdSelectionNormal Then Selection.CreateTextbox End If End Sub
Or you could actually create the TextBox and then place your text into it:
Sub AddingTextbox() Dim box As Shape Set box = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 50, 50, 100, 100) box.TextFrame.TextRange.Text = "Sample Text, Sample Text, Sample Text" End Sub
Hope that helps,
-Shelby
Shelby, does this work for MSWord or for CorelDraw? My hang up was getting the boxes in Word. Just in case someone else has this issue in the future, I had some help here:
http://www.mrexcel.com/forum/excel-questions/803182-using-macros-control-word-through-excel-other-program.html#post3929768
http://windowssecrets.com/forums/showthread.php/164123-Macro-Help-Creating-Text-Box-in-Word-from-Other-Application?p=966041#post966041
The real issue was (and still is to some extent) using reference libraries.
The example is for creating Textboxes in Word.