-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
020da8d
commit 2efd95a
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions
78
...ages/Docs/Plugin and Macros/Macros/Samples/Change font family and size/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
order: | ||
--- | ||
|
||
## Description | ||
|
||
Change font family and size on all slides in your presentation. | ||
|
||
<!-- This code snippet is shown in the screenshot. --> | ||
|
||
<!-- eslint-skip --> | ||
|
||
```ts | ||
(function () { | ||
var oPresentation = Api.GetPresentation(); | ||
for ( | ||
var slideIndex = 0; | ||
slideIndex < oPresentation.GetSlidesCount(); | ||
slideIndex++ | ||
) { | ||
var oSlide = oPresentation.GetSlideByIndex(slideIndex); | ||
var aShape = oSlide.GetAllShapes(); | ||
|
||
for (var shapeIndex = 0; shapeIndex < aShape.length; shapeIndex++) { | ||
var content = aShape[shapeIndex].GetDocContent(); | ||
// Check if content is valid before proceeding | ||
if (content) { | ||
var count = content.GetElementsCount(); | ||
for (var elementIndex = 0; elementIndex < count; elementIndex++) { | ||
var element = content.GetElement(elementIndex); | ||
// Check if element is valid before using it | ||
if (element) { | ||
element.SetFontSize(10); | ||
element.SetFontFamily("Comic Sans"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
})(); | ||
``` | ||
|
||
Methods used: GetPresentation, GetSlidesCount, GetSlideByIndex, GetAllShapes, GetDocContent, GetElementsCount, GetElement, SetFontSize, SetFontFamily | ||
|
||
## Reference Microsoft VBA macro code | ||
|
||
<!-- code generated with AI --> | ||
|
||
```vb | ||
Sub ChangeFontOnAllSlides() | ||
Dim slide As slide | ||
Dim shape As shape | ||
|
||
' Loop through each slide in the presentation | ||
For Each slide In ActivePresentation.Slides | ||
' Loop through each shape on the slide | ||
For Each shape In slide.Shapes | ||
' Check if the shape has text | ||
If shape.HasTextFrame Then | ||
If shape.TextFrame.HasText Then | ||
With shape.TextFrame.TextRange | ||
.Font.Name = "Arial" | ||
.Font.Size = 20 | ||
End With | ||
End If | ||
End If | ||
Next shape | ||
Next slide | ||
|
||
MsgBox "Font updated on all slides!", vbInformation | ||
End Sub | ||
``` | ||
|
||
## Result | ||
|
||
<!-- imgpath --> | ||
|
||
![Change font family and size](/assets/images/plugins/change-font-family-size.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters