我想使用Excel来分配可以在.AddShape
命令中定义的属性(左,上,宽度,高度)。
现在,我直接在代码中分配了属性。目标是仅使用Excel-Workbook
中的数据(左,上,宽,高)来修改属性。
例如,我在Excel中有一个包含以下数据的表,该表只能通过在Excel中编辑数据来更改形状:
Length: 500
Top: 200
Width: 50
Height: 20
我当前的代码如下:
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
我必须如何更改将从shape-properties
中的数据中提取Excel-Workbook
的代码。
感谢您的帮助!
答案 0 :(得分:1)
类似的方法将起作用:
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