I have a word document that contains text boxes (about 30 of them) that are moved around. I need to know the order of the boxes.
In Word 2016 Activedocument.Shapes returns the shapes in the order they appear in the document, however that is not the case for Word 2007 (they are in the order they were added). Since I want it to work in Office 2007 I'm looking for a workaround.
I use box.wrapformat.Type = WdWrapType.wdWrapInline to convert the boxes to act like inline shapes since .ConvertToInlineShape isn't available in office 2007 but this doesn't actually convert them to inline shapes.
Edit: I just noticed neither does .ConvertToInlineShape. The box doesn't appear in the InlineShapes collection but if I select it the selection type is wdSelectionInlineShape.
Is there a way to force Word to reassign the shapes in the shapes collection or is there another way to get references to the shapes in the correct order?
I am thinking about looping through the characters of the document (selecting each and checking the type) but this seems rather slow.
Related
Is there a reason why my MS Word VBA macro is ignoring a dropdown list I placed inside a shape (a rich text box)? I've tried referring to it by tag, name, number, etc. I even had the macro tell me the count of content controls:
MsgBox(ActiveDocument.ContentControls.Count)
I get 0.
Nothing works. If I take it out of the shape, it works fine. MS Word gives me a count of 1 item. But for some reason MS Word won't acknowledge it inside the shape. Any help on how to do this?
Edited as my previous post was completely wrong.
Each textbox in the main text story is a Shape which you can access using an index number. A shape has various properties but text etc. is in its Textframe, if it has one. But in that case the Range you need is not called Range but TextRange. So, e.g. the first contentControl in Shape 2 is
ActiveDocument.Shapes(2).TextFrame.TextRange.ContentControls(1)
You will probably need to iterate through your shapes and you may need to verify that a given shape is a textbox and/or that it has a TextFrame.
If your text box is in another Story such as a header or footer, you will probably need to identify the relevant StoryRange.
I wrote a vba macro for PowerPoint. All works well but I miss one step.
So far my macro ends by selecting a certain group of shapes on a slide. After it finishes I go back to PowerPoint and use the "Group" button to make a group out of the selected shapes.
How can I use this Micorsoft Group function in my code. I only manage to group all shapes on a slide to one group or I get an error.
I have tryed:
ActivePresentation.slide(1).shapes.selected.group
but that doesn't work.
I have read this:
How do I group a set of shapes programmatically in excel 2007 vba?
but several names of shapes are identical, so that doesn't really work. And I do not know how to store the indexnumber of a shape into a variable - which would be a second option to solve my problem.
Basically the Microsoft own functions does exactly what I would need now, right? I takes the shapes that are selected and groups them to a group. can I just call this function within my macro?
Many thanks for any help.
If you've got the shapes selected, then this should do it:
Activewindow.Selection.ShapeRange.Group
ActivePresentation.Slides(1).Shapes.Range(Array(2, 3, 4)).Group
ActivePresentation.Slides(1).Shapes.Range(Array("this", "that", "other")).Group
ActivePresentation.Slides(1).Shapes.Range(Array("this", 42, 3)).Group
Given a Microsoft Word textbox filled with formatted text, how do I use VBA to:
Iterate through the textbox content, word-by-word
At each iteration, copy/cut out that one word (including its formatting) out of the text box
Append (i.e. paste) that cut formatted word into the end of a second Microsoft Word textbox
[My situation is as follows: I have multiple continuous related texts (i.e. text + footnotes + a second set of footnotes, etc.), and my goal is to programatically lay all of that out in Word text boxes on pages of a Microsoft Word document.
I will set up the second box (that one that the words are being pasted into) to be auto-sizing, and I will then stop the "cut-paste" process once the second box gets to a certain size (which will be programatically determined based on page margins, other textboxes already occupying the page, etc.).]
I'm breaking my head over this for weeks with no results! Thanks a LOT to anyone who can send me in the right direction...
Ok, So I'm constantly battling with Microsoft as I'm creating several templates for a few customers. My problem is this, simple textbox placeholders scattered all around a document allows me to press TAB to go to the next placeholder. Much like Tab order in Visual Studio. But for some strange reason, this doesn't work with rich textbox placeholders. And I need to use rich text for a few textboxes because the user should be allowed to alter the formatting of single characters. This is not possible with simple textboxes.
So I was thinking, could this be possible using macros? For example, if a textbox placeholder is selected and the macro is run, go to the next placeholder?
The Shape/TextBox objects can be accessed through
ThisDocument.Shapes.Item(index)
and checking the returned Shape object for
theShape.Type = msoTextBox
However, the Shape objects will be returned in the order that they were created, not their order on the page/document. To find the 'next' TextBox, you are probably going to have to loop through all TextBoxes and investigate their location (.Top, .Left etc) in order to find the correct one to move to with:
theNextShape.Select
In PowerPoint 2007, PickUp/Apply does not capture some paragraph formatting, such as bullet formatting, when used programmatically (VBA). Adding the PickUp and Apply buttons to the Quick Access Toolbar (QAT) and trying this manually confirms this.
However, if you triple-click on a bulleted paragraph and select PickUp from the QAT, then go to another bullet in another shape, triple-click it, then select Apply from the QAT, the bullet formatting is successfully applied.
Programmatically, my approach was then to select all paragraphs in the source shape and use PickUp, then select all paragraphs in the target shape and use Apply. That didn't work. For example, I tried several variations on the following:
'oSource.TextFrame.TextRange.Select
oSource.TextFrame.TextRange.Paragraphs.Select
oSource.PickUp
'oTarget.TextFrame.TextRange.Select
oTarget.TextFrame.TextRange.Paragraphs.Select
oTarget.Apply
So, how can I make PopwerPowin 2007 apply the paragraph formatting in one shape to another, without copying each Paragraph property individually, either using PickUp/Apply or some other technique (in VBA, of course)?