excel - Assign shape properties from Excel in PowerPoint
问题描述
I want to assign the properties (Left, Top, Width, Height), which can be defined in the .AddShape
command, by using Excel.
Now I have assigned the properties directly in the code. The goal is to modify the properties only with data (Left, Top, Width, Height) in the Excel-Workbook
.
For example, I have a table in Excel with the following data, which changes the shape only by editing the data in Excel:
Length: 500
Top: 200
Width: 50
Height: 20
My current code looks like this:
Sub Text_EAP()
Dim WB As Workbook, wks As Worksheet
Set WB = Workbooks.Open(FileName:="U:\Automatisierung\Auto.xlsx", ReadOnly:=True)
Set wks = WB.Worksheets("Tabelle1") '<--- Here is the table with the property data
Set sld = ActivePresentation.Slides(2)
Set shp = sld.Shapes.AddShape(51, 607, 195, 70, 15) '<--- The property data here shall be changed accordingly to the Excel-Data
shp.Name = "Konzentration"
shp.Fill.ForeColor.RGB = RGB(192, 0, 0)
shp.TextFrame.TextRange.Text = "Konzentration"
shp.TextFrame.TextRange.Characters.Font.Size = 6
shp.Line.Visible = msoFalse
'Exceldatei schliessen
WB.Close SaveChanges:=False
End Sub
How do I have to change the code that the shape-properties
will be extracted from data in the Excel-Workbook
.
Thanks for your help!
解决方案
像这样的东西会起作用:
Set shp = sld.Shapes.AddShape(wks.Range("A1"), wks.Range("A2"), 195, 70, 15)
更改其他参数。
代码:
Sub Text_EAP()
Dim WB As Workbook, wks As Worksheet
Dim ex As Object
Set ex = CreateObject("Excel.Application")
Set WB = ex.Workbooks.Open(FileName:="U:\Automatisierung\Auto.xlsx", ReadOnly:=True)
Set wks = WB.Worksheets("Tabelle1")
Set sld = ActivePresentation.Slides(1)
Set shp = sld.Shapes.AddShape(wks.Range("A1"), wks.Range("A2"), 195, 70, 15) ' Change all the values & Ranges accordingly
shp.Name = "Konzentration"
shp.Fill.ForeColor.RGB = RGB(192, 0, 0)
shp.TextFrame.TextRange.Text = "Konzentration"
shp.TextFrame.TextRange.Characters.Font.Size = 6
shp.Line.Visible = msoFalse
WB.Close SaveChanges:=False
End Sub
推荐阅读
- python - 使用 sys.odcinumberlist 作为参数从 python 执行 PL/SQL 过程
- java - 如何将文本文件中的不同数据存储到 ArrayLists 中?
- security - 将任何用户文件上传到 S3 存储桶是否安全?
- javascript - 在严格模式下使用 delete 删除对象条目
- android - @Parcelize 和枚举类 - 重载解析歧义
- php - Sql 查询未在 php 中产生输出
- android - 如何检查图像视图上是否设置了背景颜色?
- c - 从命令行参数获取 unicode 符号
- oracle - Oracle中相同的表名,相同的架构,不同的用户
- jquery - 按键“输入”上的引导模式仅在 Firefox 上进行回发