简体   繁体   English

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

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

I am generating power point presentation using Excel. 我正在使用Excel生成Power Point演示文稿。 The macro is running excel. 宏正在运行excel。 It is working perfectly fine. 运行正常。 Issues is the Excel macro pasted the pictures with strange format. 问题是Excel宏以奇怪的格式粘贴了图片。 I have to use manually the command of "Reset Picture" by right clicking on each picture-->Picture format--> Reset picture 我必须通过右键单击每张图片->图片格式->重置图片来手动使用“重置图片”命令

Is it possible to make a macro power point which can do the reset picture command automatically for me? 是否可以制作一个可以自动为我执行reset picture命令的宏电源点?

THanking you advance Best regards 向您致以诚挚的问候

 '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

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

' here we are copying the pictures of logo in the respective slides '在这里,我们正在复制相应幻灯片中的徽标图片

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

Record the steps in powerpoint's macro recorder. 在powerpoint的宏记录器中记录步骤。 That will give you the basic code to paste into your excel macro. 这将为您提供粘贴到excel宏中的基本代码。 Alt T, M, R to start, same keys to stop recording. Alt T,M,R开始,相同的键停止录音。 Then Alt + F11 to open Powerpoint's VBA editor to find the code. 然后按Alt + F11打开Powerpoint的VBA编辑器以查找代码。

Also have a look at Paste Special command where you choose the format to be pasted. 还可以查看“选择性粘贴”命令,您可以在其中选择要粘贴的格式。

This is an answer I give about doing the same in VBA - VBS. 这是我在VBA-VBS中执行相同操作的答案。 For you it's easier as it's VBA - VBA. 对您来说,这很容易,因为它是VBA-VBA。 Make sure powerpoint in in the References in Excel. 确保在Excel的参考中输入powerpoint。

Record the steps in excel macro recorder. 在Excel宏记录器中记录步骤。 You have to rewrite it a bit because it uses a type of syntax that vbs doesn't. 您必须重写一下,因为它使用vbs不会使用的一种语法。

This applies (I don't have a medium9) xlRangeAutoFormatAccounting4 in vba. 这适用于(vba中的xlRangeAutoFormatAccounting4)(我没有medium9)。

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

So first look up constants in vba's object browser. 因此,首先在vba的对象浏览器中查找常量。 xlRangeAutoFormatAccounting4 = 17 xlRangeAutoFormatAccounting4 = 17

Then look the function up in object browser and look at the bottom for the function definition,. 然后在对象浏览器中查找该函数,并在底部查找函数定义。

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

So the vba becomes in vbs (and vbs works in vba) (and as you can see you can work out the correct way without needing to look the function up usually) 因此,vba会出现在vbs中(而vbs会在vba中起作用)(如您所见,您可以找到正确的方法而无需通常查找功能)

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

So your code becomes 所以你的代码变成

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

You are using Excel and you can record it in Excel and have Excel write your code. 您正在使用Excel,并且可以将其记录在Excel中并让Excel编写您的代码。

Alt + T, M, R Alt + T,M,R

then Home key then Up Arrow. 然后按Home键,然后按上箭头。 Stop recording. 停止录音。

Look what Excel wrote 看看Excel编写了什么

Selection.End(xlUp).Select

or if you had of recorded Go To dialog 或者如果您已录制了“转到”对话框

Application.Goto Reference:="R1C1"

or if you had of recorded Ctrl + Home 或如果您已录制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