簡體   English   中英

如何使用VBA宏在Powerpoint幻燈片中“重置圖片”?

[英]How to “Reset Picture” in Power point Slide using VBA macro?

我正在使用Excel生成Power Point演示文稿。 宏正在運行excel。 運行正常。 問題是Excel宏以奇怪的格式粘貼了圖片。 我必須通過右鍵單擊每張圖片->圖片格式->重置圖片來手動使用“重置圖片”命令

是否可以制作一個可以自動為我執行reset picture命令的宏電源點?

向您致以誠摯的問候

 'getting name of picture from Excel sheet cell

 logopic = ThisWorkbook.Sheets("Jan 2015").Range("z" & CellNr).Value
 apic = ThisWorkbook.Sheets("Jan 2015").Range("aa" & CellNr).Value
 mpic = ThisWorkbook.Sheets("Jan 2015").Range("ab" & CellNr).Value

如果ThisWorkbook.Sheets(“ Jan 2015”)。Range(“ z”&CellNr)> 0然后

'在這里,我們正在復制相應幻燈片中的徽標圖片

 oPP1.Slides(2).Shapes.AddPicture("" & FolderPath & "\" & logopic &    ".jpg", msoFalse, msoCTrue, 10, 10, 60, 45).Apply

在powerpoint的宏記錄器中記錄步驟。 這將為您提供粘貼到excel宏中的基本代碼。 Alt T,M,R開始,相同的鍵停止錄音。 然后按Alt + F11打開Powerpoint的VBA編輯器以查找代碼。

還可以查看“選擇性粘貼”命令,您可以在其中選擇要粘貼的格式。

這是我在VBA-VBS中執行相同操作的答案。 對您來說,這很容易,因為它是VBA-VBA。 確保在Excel的參考中輸入powerpoint。

在Excel宏記錄器中記錄步驟。 您必須重寫一下,因為它使用vbs不會使用的一種語法。

這適用於(vba中的xlRangeAutoFormatAccounting4)(我沒有medium9)。

Selection.AutoFormat Format:=xlRangeAutoFormatAccounting4, Number:=True, _
    Font:=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True

因此,首先在vba的對象瀏覽器中查找常量。 xlRangeAutoFormatAccounting4 = 17

然后在對象瀏覽器中查找該函數,並在底部查找函數定義。

Function AutoFormat([Format As XlRangeAutoFormat = xlRangeAutoFormatClassic1], [Number], [Font], [Alignment], [Border], [Pattern], [Width])

因此,vba會出現在vbs中(而vbs會在vba中起作用)(如您所見,您可以找到正確的方法而無需通常查找功能)

Selection.AutoFormat 17, True, True, True,True, True, True

所以你的代碼變成

objXLWs.Range("A3").CurrentRegion.Select.AutoFormat 17, True, True, True,True, True, True

您正在使用Excel,並且可以將其記錄在Excel中並讓Excel編寫您的代碼。

Alt + T,M,R

然后按Home鍵,然后按上箭頭。 停止錄音。

看看Excel編寫了什么

Selection.End(xlUp).Select

或者如果您已錄制了“轉到”對話框

Application.Goto Reference:="R1C1"

或如果您已錄制Ctrl + Home

Range("A1").Select
Sub InsertPictureExample()

    ' This inserts a picture at "natural" size on
    ' Slide 1 of the current active presentation

    Dim oSh As Shape

    With ActivePresentation.Slides(1)
        Set oSh = .Shapes.AddPicture("c:\temp\thing.png", msoFalse, msoTrue, 0, 0, -1, -1)
        ' position the shape if desired:
        oSh.Left = 100
        oSh.Top = 100
    End With

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM