よろずやネット

最近はLibreofficeにハマっています。

LibreOffice Calc、用紙サイズを設定する

印刷ジョブの基本、用紙サイズを設定するマクロです。
サンプルは下記の2種類。

1. Sub SetPageSize (用紙の実寸値を使用する方法)
2. Sub SetPageSize2 (列挙型(Enum)を使用する方法)

Sub SetPageSize
'	実寸を使用
	Dim oSheetStyle As Object
	oSheetStyle = ThisComponent.StyleFamilies.getByName("PageStyles").getByName("Default")
'	100 = 1mm, 1mm=100, A4: 210mm x 297mm
	oSheetStyle.Width = 21000 
	oSheetStyle.Height = 29700
End Sub

Sub SetPageSize2
'	列挙型(Enumeration Type)を使用
'	https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1view.html
	Dim oOptions(0) As New com.sun.star.beans.PropertyValue

	oOptions(0).Name = "PaperFormat"
	oOptions(0).Value = com.sun.star.view.PaperFormat.A4
	ThisComponent.Printer = oOptions()
End Sub