[Solved] Macro to change slide format from 4:3 to 16:9

Discuss the presentation application
Post Reply
mgp
Posts: 2
Joined: Tue Dec 05, 2017 10:10 am

[Solved] Macro to change slide format from 4:3 to 16:9

Post by mgp »

I am using the code below to create a new presentation with a blank slide. It works well but the slide defaults to 4:3 format. What should I add to the code to create or convert the slide into 16:9 format?
Thank you!

Code: Select all

Dim Dummy() 
Dim Url As String
Dim outDoc, outView, outSlides As Object
 
' Create blank presentation
Url = "private:factory/simpress"
outDoc = StarDesktop.loadComponentFromURL(Url, "_blank", 0, Dummy())
   outView = outDoc.getCurrentController()
   outSlides = outDoc.DrawPages
Last edited by mgp on Tue Dec 05, 2017 11:34 pm, edited 1 time in total.
OpenOffice 2.4 on Fedora 26
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Macro to change slide format from 4:3 to 16:9

Post by John_Ha »

Welcome to the forum.

Format > Page ..., and set what you want before running the macro. From memory, Format > Page cannot be recorded into a macro.

You may be better searching the Macros and UNO API forum with format page for posts like First macros for page formatting.

If your problem is solved please view your first post in this thread and click the Edit button (top right in the post) and add [Solved] in front of the subject.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Macro to change slide format from 4:3 to 16:9

Post by FJCC »

Try changing the Height and Width of the first DrawPage

Code: Select all

  oDrawPages = ThisComponent.getDrawPages()
  oObj1 = oDrawPages.getByIndex(0)
  oObj1.Height = 22860
  
  oObj1.Width = 40640
The dimensions are in units of 0.01mm, so those two settings are 9 and 16 inches.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
mgp
Posts: 2
Joined: Tue Dec 05, 2017 10:10 am

Re: Macro to change slide format from 4:3 to 16:9

Post by mgp »

Thank you! Here is what worked best!

Code: Select all

sub setpage16x9
'Changes the current slide format to 16x9.
'It sets page size which is specified in units of 0.01mm.
'Setting it to 40640x22860 (16x9in) is problematic if you merge with slides
' created manually. This is because when you set a page to 16x9 using menus
' it sets to 28002x15752.
  oDrawPages = ThisComponent.getDrawPages()
  oObj1 = oDrawPages.getByIndex(0)
'  oObj1.Height = 22860  '9in in mm * 10
'  oObj1.Width = 40640   '16in in mm * 10
  oObj1.Height = 15752   'default from slide set to 16x9
  oObj1.Width = 28002    'default from slide set to 16x9
end sub
OpenOffice 2.4 on Fedora 26
Post Reply