Get exact number in inches with LeftIndent using VBA in PowerPoint - vba

I'm trying to get a 0.3" value for the indentation before text of bullets using VBA in PowerPoint.
I'm using .ParagraphFormat.LeftIndent = 22 in my macro, but this creates a 0.31" indentation value.
21.4 gets me a 0.29" indentation and 21.5 a 0.31" - I can't figure out how to get 0.30" - any idea?
I have the same issue to get a 0.45" indentation value (I am using 33 as value but this create a 0.46" indentation)
Any idea on how to achieve this ?

Use the conversion function Application.InchesToPoints

Related

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.

Excel VBA - a macro to 'Format Data Series - Gap Width' in a chart?

I have to change the design of about 100 charts in Excel 2011, and I'm trying to speed things up a little with macros.
The problem is that Excel doesn't want to simply record some actions into a macro, it seems they need to be manually written.
I've managed to make a macro for changing the formatting of Data Labels using tips from this thread:
Formatting data labels in Excel charts using VBA
But now I'd like to also edit Label Series- Gap Width percentage, through a macro. I don't know the exact VBA syntax for this action. Maybe someone here can help.
I've tried
ActiveChart.SeriesCollection(1).DataSeries.GapWidth = "110%"
But it didn't work. Run-time error 438, Object doesn't support property or method.
Does anyone know the correct syntax?
You can try the following code:
ActiveChart.ChartGroups(1).GapWidth = 110

Excel VBA Run-time error 1004 when inserting or value formula into cell

I got the run-time 1004 error when It try to insert a formula into a cell
Range("B64").Value = "=INDEX(AK7:AK123;G74;1)"
//I also tried
Range("B64").Formula = "=INDEX(AK7:AK123;G74;1)"
//And
Range("B64").FormulaR1C1 = "=INDEX(AK7:AK123;G74;1)"
But this gives the error. If I try inserting a number or a regular string like "test" it does work, but like this it doesn't. Im new to VBA and im wondering why this would give a problem since it would never in languages im used to.
Inserting a formula with VBA requires that you use EN-US standards like,
Range("B64").Formula = "=INDEX(AK7:AK123, G74, 1)"
... or use the regional formula attribute like,
Range("B64").FormulaLocal = "=INDEX(AK7:AK123; G74; 1)"
You may have to also change INDEX to the regional equivalent. The latter is necessary when you have a system with regional settings that do not use the EN-US standard of a comma for a list separator.
see Range.FormulaLocal Property (Excel) for more information.

How do I add a subscript to a string?

I need to add a subscript (a little number next to a character, like 2 or 3 - note: not a power of...) to a string [variable]. Is this possible? I don't want the code to be lengthy as I will need to process a lot of formulas, one at a time. Thanks.
You will have to use the character set subscript numbers. Strings do not contain formatting.
http://www.fileformat.info/info/unicode/char/2082/index.htm
Is this possible? No - string variables do not contain formatting.
In order to achieve this you will need to add some sort of formatting to your string and display it in something that can show different formats - for example a RichTextBox control
Try adding a RichTextBox control and running the following line:
RichTextBox1.Rtf = "{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\fnil\fcharset0 Segoe UI;}}\viewkind4\uc1\pard\ltrpar\sa200\sl276\slmult1\f0\fs22 sometext\fs12 subscript\fs22\par\pard\ltrpar\f1\fs17\par}"
I don't claim to know what all the formatting is in here so I will leave you to figure that out yourself - hope that helps...

Write a formula in an Excel Cell using VBA

I'm trying to use VBA to write a formula into a cell in Excel.
My problem is that when I use a semicolon (;) in my formula, I get an error:
Run-time error 1004
My macro is the following :
Sub Jours_ouvres()
Dim Feuille_Document As String
Feuille_Document = "DOCUMENT"
Application.Worksheets(Feuille_Document).Range("F2").Formula = "=SUM(D2;E2)"
End Sub
You can try using FormulaLocal property instead of Formula. Then the semicolon should work.
The correct character to use in this case is a full colon (:), not a semicolon (;).
The correct character (comma or colon) depends on the purpose.
Comma (,) will sum only the two cells in question.
Colon (:) will sum all the cells within the range with corners defined by those two cells.
Treb, Matthieu's problem was caused by using Excel in a non-English language. In many language versions ";" is the correct separator. Even functions are translated (SUM can be SOMMA, SUMME or whatever depending on what language you work in). Excel will generally understand these differences and if a French-created workbook is opened by a Brazilian they will normally not have any problem.
But VBA speaks only US English so for those of us working in one (or more) foreign langauges, this can be a headache.
You and CharlesB both gave answers that would have been OK for a US user but Mikko understod the REAL problem and gave the correct answer (which was also the correct one for me too - I'm a Brit working in Italy for a German-speaking company).
I don't know why, but if you use
(...)Formula = "=SUM(D2,E2)"
(',' instead of ';'), it works.
If you step through your sub in the VB script editor (F8), you can add Range("F2").Formula to the watch window and see what the formular looks like from a VB point of view. It seems that the formular shown in Excel itself is sometimes different from the formular that VB sees...