Good afternoon,
I am trying to create a macro, which copies the shapes that I've created on my worksheet and pastes them on a specific presentation. I see my idea very clear, but I can't get it working...
All my shapes are named through typing the name at the up-left corner (as you could do to name a cell normally). All these names are listed on a specific range, and my idea is using a variable that gets that name (identifying which shape has to get) so my macro knows which shape I am referring to and then copy it, I'have been trying a lot of things but I am not capable of define which type of variable I need to use; If I type the name of the shape between quotation marks, the macro does its thing but not by a variable
Thank you for your time
Dim vName$
vName$ = .Cells(rng.Row, 6).Value
HERE IS THE PROBLEM ---> Worksheets(vSheet$).ShapesObjects(vName$).Copy
The entire code
I am trying to create a macro, which copies the shapes that I've created on my worksheet and pastes them on a specific presentation. I see my idea very clear, but I can't get it working...
All my shapes are named through typing the name at the up-left corner (as you could do to name a cell normally). All these names are listed on a specific range, and my idea is using a variable that gets that name (identifying which shape has to get) so my macro knows which shape I am referring to and then copy it, I'have been trying a lot of things but I am not capable of define which type of variable I need to use; If I type the name of the shape between quotation marks, the macro does its thing but not by a variable
Thank you for your time
Dim vName$
vName$ = .Cells(rng.Row, 6).Value
HERE IS THE PROBLEM ---> Worksheets(vSheet$).ShapesObjects(vName$).Copy
The entire code
Rich (BB code):
Sub Export()
'-----------------------------
Dim ppt_app As New PowerPoint.Application
Dim pre As PowerPoint.Presentation
Dim slde As PowerPoint.Slide
Dim shp As PowerPoint.Shape
Dim wb As Workbook
Dim rng As Range
Dim vSheet$
Dim vRange$
Dim vType$
Dim vName$
Dim vSize As Double
Dim vWidth As Double
Dim vHeight As Double
Dim vTop As Double
Dim vLeft As Double
Dim vSlide_No As Long
Dim expRng As Range
Dim adminSh As Worksheet
Dim cofigRng As Range
Dim xlfile$
Dim pptfile$
Application.DisplayAlerts = False
Set adminSh = ThisWorkbook.Sheets("Macro")
Set cofigRng = adminSh.Range("Rng_sheets")
'xlfile = adminSh.[excelPth]
pptfile = adminSh.[pptPth]
Set wb = ThisWorkbook
Set pre = ppt_app.Presentations.Open(pptfile)
For Each rng In cofigRng
With adminSh
vSheet$ = .Cells(rng.Row, 4).Value
vType$ = .Cells(rng.Row, 5).Value
'vRange$ = .Cells(rng.Row, 6).Value
vName$ = .Cells(rng.Row, 6).Value
vWidth = .Cells(rng.Row, 7).Value
vHeight = .Cells(rng.Row, 8).Value
vTop = .Cells(rng.Row, 9).Value
vLeft = .Cells(rng.Row, 10).Value
vSize = .Cells(rng.Row, 11).Value
vSlide_No = .Cells(rng.Row, 12).Value
End With
'----------------- EXPORT TO PPT
wb.Activate
Sheets(vSheet$).Activate
If vType$ = "Chart" Then
Worksheets(vSheet$).ChartObjects(vName$).Copy
Set slde = pre.Slides(vSlide_No)
With slde.Shapes.PasteSpecial(ppPasteDefault)
.Top = vTop
.Left = vLeft
.Width = vWidth
.Height = vHeight
End With
Else
Worksheets(vSheet$).ShapesObjects(vName$).Copy
Set slde = pre.Slides(vSlide_No)
With slde.Shapes.PasteSpecial(ppPasteDefault)
.Top = vTop
.Left = vLeft
.Width = vWidth
.Height = vHeight
End With
End If
Set shp = Nothing
Set slde = Nothing
Set expRng = Nothing
Application.CutCopyMode = False
Set expRng = Nothing
Next rng
pre.Save
pre.Close
Set pre = Nothing
Set ppt_app = Nothing
wb.Save
Application.DisplayAlerts = True
End Sub