2017-07-18 140 views
2

四處望着,無法找到它。需要一個宏,以便我可以在695個不同的文件上重複695次。文檔有點不安,或者我很不走運。LibreOffice中的宏將Impress幻燈片的背景更改爲純黑色

如下我能做到這一點在微軟VBA:

Sub VbaBlackies 
    Dim oSl As Slide 
    For Each oSl In ActivePresentation.Slides 
     With oSl 
      .FollowMasterBackground = msoFalse 
      .DisplayMasterShapes = msoFalse 
      With .background 
       .Fill.ForeColor.RGB = RGB(0, 0, 0) 
       .Fill.BackColor.RGB = RGB(0, 0, 0) 
       End With 
      End With 
     Next oSl 
End Sub 

我要尋找一個在LibreOffice的BASIC類似的東西。我可以這樣開始代碼:

Sub Main 
Dim oDoc As Object 
Dim oDPages As Object 
Dim oDPage As Object 
oDoc= ThisComponent 
oDPages = oDoc.getDrawPAges() 
For i=0 To oDPages.count()-1 
    oDPage = oDPages.getByIndex(i) 
    oDPage.Background = RGB(0,0,0) 'This does not work. 
    'I have no idea on how to access the object's properties and alter them. 
    Next i 
End Sub 

有什麼想法嗎?

+0

記錄變化的宏被手動完成。這可能會給你你需要的代碼。 – jsotola

+1

嘗試過,但Impress不記錄宏。 –

+0

記錄在Calc中執行類似操作的宏,更改單元格的背景顏色。給了我一些提示,但無法獲得Slide對象的「Frame」引用。 –

回答

1

您在尋找的是位於Andrew Pitonyak's macro document的代碼清單15.1,這是宏編程的重要參考。

Sub ChangeBackground 
    Dim oDoc as Object 
    oDoc = ThisComponent 
    Dim oDrawPages as Object, oDrawPage as Object 
    oDrawPages = oDoc.getDrawPages() 
    oDrawPage = oDrawPages.getByIndex(0) 
    Dim oBackground as Object 
    oBackground = oDoc.createInstance("com.sun.star.drawing.Background") 
    oBackground.FillColor = RGB(250,0,0) 
    oDrawPage.Background = oBackground 
End Sub 

API文檔位於https://www.openoffice.org/api/docs/common/ref/com/sun/star/drawing/Background.html

1

是的!像魅力一樣工作,非常感謝答案!

這是制定了我的最終代碼:

Sub Main 
Dim oDoc As Object 
Dim oDPages As Object 
Dim oDPage As Object 

oDoc = ThisComponent 
oDPages = oDoc.getDrawPAges() 

For i=0 To oDPages.count()-1 
    oDPage = oDPages.getByIndex(i) 
    Dim oBackground As Object 
    oBackground = oDoc.createInstance("com.sun.star.drawing.Background") 
    oBackground.FillColor = RGB(0,0,0) 
    oDPage.Background = oBackground 
    Next i 
End Sub