VBA PowerPoint Table Cell's Format - vba

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.

Related

valign images in xlsxwriter cell

Is there any hack for v-aligning images in a cell
I am trying to create a dashboard,those traffic lights are images.
Since once of the columns is a text-wrap and the height of those rows
are dynamic, I have no way of knowing the row height to calculate the y_offset for those images
Does anyone have a recommendation on how I can handle this? Is there a way of getting the row_height after sheet.write and text_wrap format is applied?
Is there a way of getting the row_height after sheet.write and text_wrap format is applied?
Probably not without access to Windows APIs for calculating bounding boxes for strings.
You could probably make some working estimates based on the length of your string. Each new line in text wrap is equal to 15 character units or 20 pixels.
Since once of the columns is a text-wrap and the height of those rows are dynamic, I have no way of knowing the row height to calculate the y_offset for those images
This is the main problem. In order to specify the image position exactly you will need to specify explicit row heights so that XlsxWriter can calculate where the image will go based on the size of the cell. In order words you will have to avoid the automatic row height that Excel gives you when wrapping text.
Once the row height is fixed you can position images exactly where you want them using the 'x_offset' and 'y_offset' options.
Note, you can also use conditional formatting to create traffic lights based on cell values. See Sheet9/Example 9 of this code from the XlsxWriter docs and image below. These can be centered automatically even with with text wrapping.

Powerpoint VBA - Autofit columns

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

Adding a background image to a particular cell

I tried to insert the background image using following code:
Pic = "C://Picture/Logo1"
Activesheet.SetBackgroundPicture Pic
This inserts the picture to full sheet but I want to add it to particular cell or a range of cells. Please help
As far as I know excel doesn't support appending the image to a cell (with or without VBA).
The background of a single cell supports colors/gradients/fill-patters, but not the pictures.
It is possible however, to "place" the picture (shape) object with the same width and height right above the cell and make it locked and move around together with the cell if somebody attempts to resize cell widths. I personally wouldn't go that way, too much to code and too much risk of breaking the structure.

How to change data label width in an Excel chart with VBA?

I want to change a label width in Excel chart by VBA code:
set lbl = SERIES1. points(1).datalabel
msgbox lbl.width 'this is working
lbl.width = 40 ' compile error: wrong number of arguments or invalid property assignment
I can get the label width but cannot change it. What am I doing wrong?
AFAIK, the width of a chart data point label is not configurable. Even though the width can be retrieved with VBA, it's not possible to set or change it with a VBA command or property.
According to the documentation, the DataLabels.Width property is read only.
Returns the width, in points, of the object. Read-only.
Source
Excel chart labels remain stubbornly uncooperative and resist formatting attempts, be it with VBA or with the UI.
That's (unfortunately) just how Excel works.
Don't shoot the messenger.
If you want to make a difference, consider raising an idea at excel.uservoice.com
This works in Excel 2016, you'll just need to adjust the series collection and point numbers to fit your needs. ActiveChart.FullSeriesCollection(1).Points(1).DataLabel.Width = 363.314.

Prevent vba generated PowerPoint table from auto-sizing rows

I have a large macro that generates and populates a table in powerpoint based on excel values. I manually resize the rows based on specific parameters, but I've run into the very annoying issue that I cannot seem to prevent the rows from auto-resizing if the text would overflow from that particular cell. I've tried using the textframe and textframe2 "autosize" property but this gives an error on the first call saying that the specified value is out of range. The error number is -2147024809 (80070057), although I doubt that will be of any use. Is there a way to prevent this autosizing beyond writing code to manually shorten the text when it will overflow?
RGA,
the answer to your question is yes; you can do this. This topic is discussed in the following thread: Understanding format of tables in PowerPoint (VBA 2010) (resize text to cell)
However, I don't know if this technique still 'works' for ppt 2016. I had such code implemented, and then I 'upgraded' to office 2016; now it doesn't work.
With that being said, this was my code (resized the text until it 'fit'):
...
Do Until (table.rows(1).height + table.rows(2).height < TABLE_HEIGHT) or (table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size = 1)
If table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size = 1 Then
table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size = 27
table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size = table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size - 1
table.Cell(2, 3).Shape.TextFrame.TextRange.Font.size = table.Cell(2, 2).Shape.TextFrame.TextRange.Font.size
Else
table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size = table.Cell(1, 1).Shape.TextFrame.TextRange.Font.size - 1
End If
Loop
In order to restore some functionality in ppt 2016, I decided to rewrite my code to limit the number of lines shown to prevent the 'resize' table call:
...
table.Cell(1, 1).Shape.TextFrame.TextRange = table.Cell(1, 1).Shape.TextFrame.TextRange.lines(1,2)
table.Cell(2, 2).Shape.TextFrame.TextRange = table.Cell(2,2).Shape.TextFrame.TextRange.lines(1,1)
table.Cell(2, 3).Shape.TextFrame.TextRange = table.Cell(2, 3).Shape.TextFrame.TextRange.lines(1,1)
In theory, you can use the .height; .Textrange; and the height of your font to figure the size of font you need inorder to 'shrink' the text to fit.
What do you want to happen when there is too much text to fit into a cell? There is no UI concept in PowerPoint to prevent row auto resizing based on cell overflow as there is nowhere for the additional text to go as demonstrated by typing in a cell within PowerPoint. Therefore there is no API to do the same. I would record the row before and after inserting the text and truncate word by word as you say until the row height returns to the original value.