Powerpoint VBA - Autofit columns - vba

I'm really a beginner at vba, but I've been puzzling around how to make it work. I'm creating a powerpoint presentation with Excel vba, based on data in an excel sheet a table is created on a slide in a newly created powerpoint presentation. I've got the table formatting done, which is a real hassle, by going over each individual cell and formatting them (looping, but still)....
The only thing missing is the individual column width. Based on the input data some columns might change in width,
Because of this reason I would like to have an autofit on the columns only. The rows should remain 1 line in height. But the column width should adapt to whatever would be necessary to keep the row height on 1 line.
Dim PPTtable1 As PowerPoint.Shape
With PPTtable1
.Left = 350
.Top = 150
.Width = 758
.table.Columns(1).Width = Auto
.table.Columns(2).Width = Auto
.table.Columns(3).Width = Auto
End With
This would turn the columns in the smallest possible width by stretching the height of the cells. Basically what I need is the function of double clicking on the side border of a column, and it will automatically fit to the correct width.
EDIT:
Maybe this would be interesting and important to know the order of the code:
Table is created
Format of the individual cells (bold, italic, size, font, etc...)
Data is filled in from an excel sheet
Trying to autosize the column

Related

VBA PowerPoint Table Cell's Format

I have been looking everywhere for this solution but can't seem to find it anywhere.
I want to access these offsets percentage of the cell so I can make the image smaller
But when I use this code
With $SHP.Table.Cell(1, $i).Shape.Fill
.TextureOffsetX = 25
.TextureOffsetY = 25
Endwith
This happens:
Texture tile turns to true and my picture is being repeated itself.

How to fit column width in macro?

I wrote a macro which copies table from excel to word. In excel all columns have different width. In Word I want to fit my table to one page - margins in Word are 1.5 cm from left and right. Number of rows in my table changes, number of columns is stable (this is 14). How can I set column width to be equal? I wonder if it's possible to set the same column width regardless of the amount of text in headlines. I create swdth variable which I then divide by 14 (all my columns) and I have my table on one page...
This code doesn't work properly. I have all rows in one page, but columns have different width.
Table.Rows.SetHeight RowHeight:=InchesToPoints(0.17), HeightRule:=wdRowHeightExactly
Table.Rows(1).SetHeight RowHeight:=InchesToPoints(0.59), HeightRule:=wdRowHeightExactly
sWdth = InchesToPoints(6.22)
WordTable.PreferredWidthType = wdPreferredWidthPoints
WordTable.PreferredWidth = sWdth
sWdth = sWdth / 14
Giving all columns the same with is as simple as:
Table.Columns.DistributeWidth
but it's not apparent what this has to do with keeping the table on one page.
I've seen similar questions recently. As always...
#1) Turn on the Macro Recorder
#2) Click through the steps you need to perform
#3) Turn off the Macro Recorder
Hit Alt+F11 and you should see all the code you need to do whatever you want to do. Remember, the Macro Recorder is your friend!

excel rowheight - a bug here?

Excel seems to work with the row heights in the following (il)logic:
If you refer to a single cell and your cell is defined "Wrap Text" and the row height is "Autofit":
When you enter more characters than what can fit to the cell width the row in the cell is changed automatically and in the end, when you press "Enter", the row height is expanded so that the whole text is visible.
If you refer to combined cells and your cell combination is "Wrap text" and "Autofit":
When you enter more characters than what can fit to the combined cells' width the row is NOT changed automatically and after "Enter" the row height is NOT adjusted to show the whole text.
I think this is not logical.
What would be the trick to get excel to automatically adjust the row height also in the case of "Wrap Text" combined cells? Any VBA solutions? (Basically you could, maybe, count how many line changes the combined cell has and adjust the rows.height property accordingly but...

Excel VBA Resize group

After executing some deleting rows in VBA, a shape size (group) changes height, but is there a way to do this in VBA rather than in the sheet itself. I've assigned it a Macro (Group1), but I am uncertain what to do next. Any suggestions?
Set shape properties to Don't move or size with cells
Shapes("YourShapename").Placement = xlFreeFloating

Inserting 2 Images in a Single Cell

I am new to VBA and request your assistance for the below query.
QUERY:
I want to insert two images, one below the other, in a Cell say B2 with already pre-configured enough Cell height and width.
I am using the below code
.Left = ActiveSheet.Range("B2").Left
.Top = ActiveSheet.Range("B2").Top
where in my 1st image is placed at the Top,Left of the Cell.Now how do i place the 2nd image in the same cell below the 1st image.
Is there any command like .Bottom?
There is no command like .Bottom, but an alternate approach for you could be simply adding the height of the first image to the top of the cell to decide where it ends. I.e.:
image2.Top = ActiveSheet.Range("B2").Top + image1.Height