如何将图片添加到Powerpoint演示文稿图片占位符?

2023-12-14

我在 Excel VBA 中创建了一些代码,为 Excel 的每一行创建 PowerPoint 演示文稿 1 幻灯片,并填充到 PowerPoint 中的特定文本框中。
我现在想添加所有与描述匹配的图像。这些都是 Jpeg,而不是图表等。
我该如何做到这一点?在 excel 中执行此操作更好,还是本身执行此 Powerpoint VBA 更好?
不管怎样,有人能帮我写一些关于如何做到这一点的代码吗?
图像框架已存在于 PowerPoint 中。每张幻灯片有 2 张图像(没有过渡或其他任何内容)。
谢谢你!

P.S 我在 Windows 7 上使用 PowerPoint 和 Excel 2010。


有没有办法从 Excel 中做到这一点?我的其余代码位于 Excel 中,如果能将其作为宏的一部分来实现那就太好了。
基本上我有一个我想使用的文件位置,例如C:\insertfoldername\imagename.jpeg 显示在电子表格的 H 列中(大约 400 行)。
我正在使用的 Powerpoint 模板具有图像框架(Powerpoint 中的图像框架,当您将鼠标悬停在它上面时会显示......“从文件插入图片”。
它们的尺寸已经确定并且位于正确的位置。
我想要做的是,在 Excel 中,从 Excel 中的文件路径粘贴图像并将其粘贴到特定的图像框架中。
这有可能吗?

基本上可以做到这一点:
PPT.ActivePresentation.Slides(2).Shapes(3)LoadImage(spath)

下面是我正在使用的代码。
**** 表示文件路径。 jpg 文件被设置为 Excel 电子表格中的第三列。

Sub CreateSlides()
'Dim the Excel objects
Dim objWorkbook As New Excel.Workbook
Dim objWorksheet As Excel.Worksheet

'Dim the File Path String
Dim strFilePath As String

'Dim the PowerPoint objects
Dim PPT As Object
Dim pptSlide As PowerPoint.Slide
Dim pptLayout As PowerPoint.CustomLayout
Dim pptNewSlide As PowerPoint.Slide
Dim str As String
Dim Title As String

Set PPT = GetObject(, "PowerPoint.Application")

PPT.Visible = True

'Get the layout of the first slide and set a CustomLayout object
Set pptLayout = PPT.ActivePresentation.Slides(1).CustomLayout

'Run the OpenFile function to get an Open File dialog box. It returns a String containing the file and path.
strFilePath = OpenFile()

'Open the Excel file
Set objWorkbook = Excel.Application.Workbooks.Open(strFilePath)

'Grab the first Worksheet in the Workbook
Set objWorksheet = objWorkbook.Worksheets(1)

'Loop through each used row in Column A
For i = 2 To objWorksheet.Range("A65536").End(xlUp).Row

Set PPT = GetObject(, "PowerPoint.Application")

Set pptNewSlide = PPT.ActivePresentation.Slides.AddSlide(PPT.ActivePresentation.Slides.Count + 1, pptLayout)

 'Get the number of columns in use on the current row
    Dim LastCol As Long
    Dim boldWords As String

    boldWords = "Line1: ,line2: ,Line3: ,Line4: "
    LastCol = objWorksheet.Rows(i).End(xlToRight).Column
    If LastCol = 16384 Then LastCol = 1 'For some reason if only column 1 has data it returns 16384, so correct it

    'Build a string of all the columns on the row
    str = ""
    str = "Line1: " & str & objWorksheet.Cells(i, 1).Value & Chr(13) & _
    "Line2: " & objWorksheet.Cells(i, 2).Value & Chr(13) & _
    "Line3: " & objWorksheet.Cells(i, 10).Value & Chr(13) & _
    "Line4: " & objWorksheet.Cells(i, 7).Value & Chr(13) & Chr(13) & _
    objWorksheet.Cells(i, 14).Value

 sfile = Cells(i, 3) & ".jpg" **** This is the jpg name

Set PPT = GetObject(, "PowerPoint.Application")

spath = "C:\test\"

'Write the string to the slide
pptNewSlide.Shapes(2).TextFrame.TextRange.Text = objWorksheet.Cells(i, 3).Value 'This enters the film Title
PPT.ActivePresentation.Slides(PPT.ActivePresentation.Slides.Count).Shapes(1).TextFrame.TextRange.Text = str


BoldSomeWords PPT.ActivePresentation.Slides(PPT.ActivePresentation.Slides.Count).Shapes(1), str, boldWords

'This is where I want to load in the Image.
'PPT.ActivePresentation.Slides(PPT.ActivePresentation.Slides.Count).Shapes(3).Picture = LoadPicture(spath) ' & sfile)
'PPT.ActivePresentation.Slides(2).Shapes(3)LoadImage((spath))

Next
End Sub

Function OpenFile()
'Dim the File Dialog object and string
Dim objFileDialog As FileDialog
Dim strFile As String

'Set the objFileDialog to an instance of the FileDialog object
Set objFileDialog = Application.FileDialog(msoFileDialogFilePicker)

'Set the Properties of the objFileDialog object
objFileDialog.AllowMultiSelect = False
objFileDialog.ButtonName = "Select"
objFileDialog.InitialView = msoFileDialogViewDetails
objFileDialog.Title = "Select Excel File"
objFileDialog.InitialFileName = "C:\"
objFileDialog.Filters.Clear
objFileDialog.Filters.Add "Excel", "*.xls; *.xlsx", 1
objFileDialog.FilterIndex = 1

'Show the FileDialog box
objFileDialog.Show

'Set strFile to the first record of the SelectedItems property of our FileDialog
strFile = objFileDialog.SelectedItems(1)

'Return the File Path string
OpenFile = strFile
End Function

虽然那好像当您将图像添加到带有空图片或内容占位符的幻灯片时,它会起作用,它总是会进入该占位符并调整大小以适应。

你只需要像这样添加它:

osld.Shapes.AddPicture "Path", msoFalse, msoTrue, -1, -1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将图片添加到Powerpoint演示文稿图片占位符? 的相关文章

  • Excel 中使用通配符 {*} 进行 Vlookup

    我有下表 现在 我想检查主题是否具有数据中存在的任何文本 col F I used VLOOKUP A2 F F 1 0 但它正在给予 N A Try 公式为B2 SUM COUNTIF A2 F 2 F 3 gt 0 Edit SUM C
  • 如何暂停特定时间? (Excel/VBA)

    我有一个 Excel 工作表 其中包含以下宏 我想每秒循环一次 但如果我能找到执行此操作的函数 那就很危险了 难道不可能吗 Sub Macro1 Macro1 Macro Do Calculate Here I want to wait f
  • 二维数组作为字典的项目

    我想用一个项目的几个属性填充字典 例子 我正在考虑拥有Item 1 and Item 2 as Dictionary键与array这将保留其属性 我需要能够单独访问项目的每个属性 因此将它们连接为一个字符串不是一种选择 我正在考虑类似下面的
  • 如何VBA等待Windows保存对话框和发送密钥

    我正在创建一个宏文件 用于下载并保存从 SAP 旧版本 7 20 中提取的数据 当出现保存对话框时 未检测到 Windows 对话框 因为我的客户端 SAP 版本是旧版本 7 20 现在我对此的解决方案是发送密钥 但问题是某些数据包含大量数
  • 如何获取 pandas 数据框并覆盖 Excel 工作簿中的特定工作表

    我想获取一个数据框并让它替换特定工作表中的现有数据 假设为sheet1 然后我想获取另一个数据框并将其附加到另一张工作表上的数据 比如说同一工作簿中的sheet2 目前 我必须将数据写入新的 Excel 工作簿 我无法在线找到如何实际替换我
  • VBA 中的求和函数

    我在 vba 中对单元格求和时遇到问题 我需要使用单元格 a b Range A1 function SUM Range Cells 2 1 Cells 3 2 但它不起作用 函数不是范围内的属性 方法 如果您想对值求和 请使用以下命令 R
  • 查看 Excel 是否处于 .NET 中的单元格编辑模式的解决方法

    我有一个用 VB NET 编写的应用程序 它通过互操作与 Excel 进行交互 我最终遇到了单元格编辑模式的已知问题 请参阅 and 堆栈溢出 https stackoverflow com questions 221984 how to
  • 使用 C# 在 Excel 中查找和替换文本

    我想使用 C 在 Excel 中查找并替换一组文本 而且我希望此替换仅发生在第一行中的文本 我已经使用Google并找到了一些付费资源 例如Aspose API Spire Xls等 但我正在寻找开源资源或任何其他有效的方法来实现这一目标
  • 在 Python 中绘制 Excel 中的数据

    我必须从 Excel 文件中读取和绘制数据的代码是这样的 import pandas as pd import matplotlib pyplot as plt excel file file1 xlsx file1 pd read exc
  • Excel宏隐藏特定单元格和合并区域

    我试图根据另一个单元格的值隐藏特定单元格 到目前为止 我设法隐藏整行 但无法隐藏特定单元格 Local Currency value show hide item If Range Currency Value USD Then Range
  • 使用 FileSystemObject 读取和写入 csv 文件

    是否可以使用 VBA 中的 FileSystemObject 读取和写入 csv 文件 必然是 基本语法如 Set objFSO CreateObject scripting filesystemobject create a csv fi
  • 通过 Excel VBA 保存并关闭 powerpoint

    下面的代码根据定义的名称创建多个图表 然后打开具有这些定义的名称的 powerpoint 文件并转储到图表中 除了最后一部分之外 一切都正常 保存并关闭文件 我已将尝试保存和关闭文件的尝试标记为绿色 任何帮助表示赞赏 Sub Slide19
  • VB:在 Adob​​e Illustrator、Photoshop 中分配给布尔属性

    在使用 VBA 自动化 Adob e Illustrator CS3 时 我发现分配一个布尔变量 to a 布尔属性结果总是分配 False Dim New Path As Illustrator PathItem Dim v As Boo
  • 在单元格更改时循环遍历一系列单元格,以将序列中的下一个数字显示为单元格的新值

    我了解如何循环范围 For Each cell In Range A1 A5 If condition Then End If Next 我知道 OnChange 事件 Private Sub Worksheet Change ByVal
  • Excel,循环遍历 XLSM 文件并将行复制到另一个工作表

    我现在遇到的此代码的主要问题是处理我打开的 xlsm 文件的错误 我对这些文件的 VB 代码没有编辑权限 如果 vb 出错 有没有办法跳过文件 我有一个包含大约 99 个 xlsm 文件的文件夹 我希望循环遍历每个文件并复制每个工作簿中的第
  • 用于导出到 CSV/Excel 的数据 URI(无服务器端请求):浏览器支持/限制?

    以下问题 Javascript 或 Flash 导出至 CSV Excel https stackoverflow com questions 8150516 javascript or flash export to csv excel
  • VB FFT - 难以理解结果与频率的关系

    试图理解我正在使用的 fft 快速傅里叶变换 例程 窃取 回收 输入是 512 个数据点的数组 它们是样本波形 测试数据生成到该数组中 fft 将该数组变换到频域 尝试理解频率 周期 采样率和 fft 数组中位置之间的关系 我用例子来说明
  • 将 CSV 导入 Excel - 自动“文本到列”和“插入表格”

    我想在 Excel 2010 上打开 CSV 逗号分隔 文件并自动将文本转换为列 然后选择所有活动单元格并插入带标题的表格 是否可以在我的功能区中添加一个按钮来为我完成这一切 我经常使用不同大小的 CSV 文件 我发现每次手动执行此操作有点
  • VBA 写入文件时对数值进行四舍五入 - 如何防止?

    在下面的代码中 我在确保文件编写器不会将我的数字四舍五入到一定的小数位数时遇到问题 我需要使用变体 因为有时该值是字符串 有时它是数字 我怎样才能强制它准确地写出变量是什么 例如 下面的代码可能显示 0 00038 我想显示确切的值 Dim
  • 在 ASP.Net Core 2.0 中导出到 Excel

    我曾经使用下面的代码在 ASP NET MVC 中将数据导出到 Excel Response AppendHeader content disposition attachment filename ExportedHtml xls Res

随机推荐