PDA

View Full Version : Stack textboxes together?



JensP
10-12-2014, 11:25 AM
Hi,

I need your help! I want an macro, that can do the following:

If I selct two or more text boxes in a row I would like to have a button (macro) that takes all the boxes that I selected and puts them directly next to each other. Only the width of one pixel should be between one text-box and the next one.

The same - a second one - for boxes that are above or below - vertically - next to each other.

Is that possible?

Many thanks for your help.

SamT
10-12-2014, 03:06 PM
I don't believe so. I just tried to select multiple controls on a running form and couldn't.

It is possible to have (a) button(s) that will move controls that are chosen at design time.

Cosmo
10-15-2014, 01:52 PM
Try th is:


Option Explicit


Sub DistributeHorizontalSpace()
Dim buffer As Single
Dim oShp As Shape
Dim l As Single
buffer = 2 ' Change this to the distance you wish between the shapes.

With ActiveWindow.Selection
.ShapeRange.Align msoAlignLefts, False
For Each oShp In .ShapeRange
oShp.Left = oShp.Left + l
l = l + oShp.Width + buffer
Next oShp
End With

End Sub

SamT
10-15-2014, 03:52 PM
@ Cosmo: OK, I was thinking of VBA UserForm Textboxes, not Worksheet Form Controls.

Cosmo
10-16-2014, 05:46 AM
Sorry, I didn't see anything in the message that referenced a userForm, I assumed yo were talking about the text frames in the presentation.

You possibly can do this, using the vbproject object model (you need to set the option to allow programmatic access to the VB Project). I have only used this to access code modules, but check the following to see if you can adapt my code to work with the userform:

activepresentation.vbproject.VBE.activeCodePane or 'activepresentation.vbproject.VBE.activeWindow might give you access to the currently active form, the VBForm object has a .SelectedVBCOntrols collection which should give you the selected VBContol objects, and the VBControl object should allow you to set the top/left properties.

SamT
10-16-2014, 05:55 AM
We still don't know what the OP needs, because they haven't been back in 4 days.

JensP
10-16-2014, 12:42 PM
Sorry for not replying that fast.

I do not know what type of text boxes you are taling about. But in PowerPoint I only know one type. It is found in "Insert"-->"Shapes"-->"TextBox". So which one should I try?

Many thanks.

Cosmo
10-16-2014, 12:54 PM
Try what I posted in post #3

SamT
10-16-2014, 01:03 PM
What Cosmo says.

JensP
10-24-2014, 02:02 PM
Hi all

that worked very well. many thanks. to do the same in a vertical direction I guess I need to change the code? I give it a shot even though I do not have a clou:


Option Explicit


Sub DistributeVerticalSpace()
Dim buffer As Single
Dim oShp As Shape
Dim l As Single
buffer = 2 ' Change this to the distance you wish between the shapes.

With ActiveWindow.Selection
.ShapeRange.Align msoAlignUps, False
For Each oShp In .ShapeRange
oShp.Up = oShp.Up + l
l = l + oShp.Hight+ buffer
Next oShp
End With

End Sub

Does that will work? Many thanks for your help. I already can see that there is a next topic where I need help. I want to have a macro that will put all margins of all the selected textboxes to zero (0)
How would that be possible? Many thanks.

John Wilson
11-01-2014, 01:18 AM
Not a bad try!


Sub DistributeVerticalSpace()
Dim buffer As Single
Dim oShp As Shape
Dim l As Single
buffer = 2 ' Change this to the distance you wish between the shapes.

With ActiveWindow.Selection
.ShapeRange.Align msoAlignTops, False
For Each oShp In .ShapeRange
oShp.Top = oShp.Top + l
l = l + oShp.Height + buffer
Next oShp
End With

With ActiveWindow.Selection.ShapeRange.TextFrame
.MarginBottom = 0
.MarginLeft = 0
.MarginTop = 0
.MarginRight = 0
End With

End Sub

John Wilson
11-01-2014, 01:23 AM
Not a bad try! SORRY about double post!


Sub DistributeVerticalSpace()
Dim buffer As Single
Dim oShp As Shape
Dim l As Single
buffer = 2 ' Change this to the distance you wish between the shapes.

With ActiveWindow.Selection
.ShapeRange.Align msoAlignTops, False
For Each oShp In .ShapeRange
oShp.Top = oShp.Top + l
l = l + oShp.Height + buffer
Next oShp
End With

With ActiveWindow.Selection.ShapeRange.TextFrame
.MarginBottom = 0
.MarginLeft = 0
.MarginTop = 0
.MarginRight = 0
End With

End Sub