PowerPoint update from Excel VBA works in PPT not Excel

smarble

New Member
Joined
May 6, 2010
Messages
1
I am so chapped and baffeled by this code. I made it work from VBA in Powerpoint but when I transfered into Excel the same lines don't work. BEAR IN MIND THIS DOES WORK NOW. :confused: What is even more baffeling is the lines work in the Immediate Window but not in the code. Even worse the same lines may or might not work. I will paste in my code and then the offending lines will be grouped. I would really appreciate help. You might notice from the remarked lines what I had that I have tried.

Code:
Sub updatepowerpoint()
Dim objppt As PowerPoint.Application
Dim pwpt As PowerPoint.Presentation
Set objppt = CreateObject("PowerPoint.Application")
objppt.Visible = msoTrue
Set pwpt = objppt.Presentations.Open2007("c:\tdg_template.pptm")
Dim oslide1 As Slide
Dim oslide2 As Slide
Dim opicture As Variant
Dim opicture2 As Shape
Dim date1, date2, date3, date4, date5, date6 As String
Dim d1year, d2year, d3year, d4year, d5year, d6year As String
    
    date1 = Format(Date, "mmm")
    date2 = Format(DateAdd("m", 1, Date), "mmm")
    date3 = Format(DateAdd("m", 2, Date), "mmm")
    date4 = Format(DateAdd("m", 3, Date), "mmm")
    date5 = Format(DateAdd("m", 4, Date), "mmm")
    date6 = Format(DateAdd("m", 5, Date), "mmm")
    d1year = Format(Date, "yyyy")
    d2year = Format(DateAdd("m", 1, Date), "yyyy")
    d3year = Format(DateAdd("m", 2, Date), "yyyy")
    d4year = Format(DateAdd("m", 3, Date), "yyyy")
    d5year = Format(DateAdd("m", 4, Date), "yyyy")
    d6year = Format(DateAdd("m", 5, Date), "yyyy")
    
    lmon1 = Len(date1)
    lmon2 = Len(date2)
    lmon3 = Len(date3)
    lmon4 = Len(date4)
    lmon5 = Len(date5)
    lmon6 = Len(date6)
    lyear1 = Len(d1year)
    lyear2 = Len(d2year)
    lyear3 = Len(d3year)
    lyear4 = Len(d4year)
    lyear5 = Len(d5year)
    lyear6 = Len(d6year)
 
Set oslide1 = pwpt.Slides(1)
Set oslide2 = pwpt.Slides(2)
'.Item(1)
'Set oslide2 = pwpt.Slides.Item(2)
'Set oslide2 = ActiveWindow.Presentation.Slides(2)
Set opicture = pwpt.Slides(1).Shapes("MonthShape1")
'oslide1.Shapes("MonthShape1")
'oslide1.Shapes.Item ("MonthShape1")
'Set opicture = oslide1.Shapes.Item("MonthShape1")
'1
With opicture
.TextFrame.TextRange.Text = date1 & d1year
.TextFrame.TextRange.Font.size = 40
.TextFrame.TextRange.Font.Name = "Engravers MT"
.TextFrame.TextRange.ParagraphFormat.Bullet = msoTrue
.TextFrame.TextRange.Characters(Start:=lmon1 + 1, Length:=lyear1).Font.size = 14
.TextFrame.TextRange.Characters(Start:=lmon1 + 1, Length:=lyear1).Font.Name = "Arial Unicode MS"
.TextFrame.TextRange.Characters(Start:=lmon1 + 1, Length:=lyear1).Font.BaselineOffset = 0.82
End With
'2
Set opicture = oslide1.Shapes.Item("MonthShape2")
With opicture
.TextFrame.TextRange.Text = date2 & d2year
.TextFrame.TextRange.Font.size = 40
.TextFrame.TextRange.Font.Name = "Engravers MT"
.TextFrame.TextRange.ParagraphFormat.Bullet = msoTrue
.TextFrame.TextRange.Characters(Start:=lmon2 + 1, Length:=lyear2).Font.size = 14
.TextFrame.TextRange.Characters(Start:=lmon2 + 1, Length:=lyear2).Font.Name = "Arial Unicode MS"
.TextFrame.TextRange.Characters(Start:=lmon2 + 1, Length:=lyear2).Font.BaselineOffset = 0.82
End With
'3
Set opicture = oslide1.Shapes.Item("MonthShape3")
With opicture
.TextFrame.TextRange.Text = date3 & d3year
.TextFrame.TextRange.Font.size = 40
.TextFrame.TextRange.Font.Name = "Engravers MT"
.TextFrame.TextRange.ParagraphFormat.Bullet = msoTrue
.TextFrame.TextRange.Characters(Start:=lmon3 + 1, Length:=lyear3).Font.size = 14
.TextFrame.TextRange.Characters(Start:=lmon3 + 1, Length:=lyear3).Font.Name = "Arial Unicode MS"
.TextFrame.TextRange.Characters(Start:=lmon3 + 1, Length:=lyear3).Font.BaselineOffset = 0.82
End With
'4
Set opicture = pwpt.Slides(2).Shapes("MonthShape4")
'Set opicture = oslide2.Shapes.Item("MonthShape4")
With opicture
.TextFrame.TextRange.Text = date4 & d4year
.TextFrame.TextRange.Font.size = 40
.TextFrame.TextRange.Font.Name = "Engravers MT"
.TextFrame.TextRange.ParagraphFormat.Bullet = msoTrue
.TextFrame.TextRange.Characters(Start:=lmon4 + 1, Length:=lyear4).Font.size = 14
.TextFrame.TextRange.Characters(Start:=lmon4 + 1, Length:=lyear4).Font.Name = "Arial Unicode MS"
.TextFrame.TextRange.Characters(Start:=lmon4 + 1, Length:=lyear4).Font.BaselineOffset = 0.82
End With
'5
Set opicture = oslide2.Shapes.Item("MonthShape5")
With opicture
.TextFrame.TextRange.Text = date5 & d5year
.TextFrame.TextRange.Font.size = 40
.TextFrame.TextRange.Font.Name = "Engravers MT"
.TextFrame.TextRange.ParagraphFormat.Bullet = msoTrue
.TextFrame.TextRange.Characters(Start:=lmon5 + 1, Length:=lyear5).Font.size = 14
.TextFrame.TextRange.Characters(Start:=lmon5 + 1, Length:=lyear5).Font.Name = "Arial Unicode MS"
.TextFrame.TextRange.Characters(Start:=lmon5 + 1, Length:=lyear5).Font.BaselineOffset = 0.82
End With
'6
Set opicture = oslide2.Shapes.Item("MonthShape6")
With opicture
.TextFrame.TextRange.Text = date6 & d6year
.TextFrame.TextRange.Font.size = 40
.TextFrame.TextRange.Font.Name = "Engravers MT"
.TextFrame.TextRange.ParagraphFormat.Bullet = msoTrue
.TextFrame.TextRange.Characters(Start:=lmon6 + 1, Length:=lyear6).Font.size = 14
.TextFrame.TextRange.Characters(Start:=lmon6 + 1, Length:=lyear6).Font.Name = "Arial Unicode MS"
.TextFrame.TextRange.Characters(Start:=lmon6 + 1, Length:=lyear6).Font.BaselineOffset = 0.82
End With
End Sub

I tried to set oslide to the slide then use opicture with oslide. Check out these lines that work. But here is the madness I can't use the syntax of MonthShape2 on MonthShape1 or MonthShape4. This is crazy.

The following lines were cut from the code above. Bear in mind this code finally works I just don't understand why the code can't all look like it does for monthshapes 2 3 5 6.

Code:
Set opicture = pwpt.Slides(1).Shapes("MonthShape1")
Set opicture = oslide1.Shapes.Item("MonthShape2")
Set opicture = oslide1.Shapes.Item("MonthShape3")
Set opicture = pwpt.Slides(2).Shapes("MonthShape4")
Set opicture = oslide2.Shapes.Item("MonthShape5")
Set opicture = oslide2.Shapes.Item("MonthShape6")

I am using Office 2007, Excel and PowerPoint. Windows XP. :confused:
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,978
Messages
5,767,426
Members
425,412
Latest member
andrealp4444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top