Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excell update to Powerpoint not consistent 1

Status
Not open for further replies.

wan1ord

MIS
Apr 20, 2010
7
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. 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

</code>

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")
</code>
 

Hi,

Please explain, "lines don't work."

Does that mean there was an ERROR? If so, what exact error on what exact statement?

Does that mean that the result was not as expected? If so, what exact result?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Well Skip I commend you for your bravery! Actually I unremarked the very lines of code that were create an error last night and ran the code to recreate the error so I could share it with you. Low and behold they worked, I can't reproduce the problem I was having last night!!

Last night with the code

Set opicture = oslide1.Shapes.Item("MonthShape1")

I was getting a run time error 13.

after I changed the line to read:

Set opicture = pwpt.Slides(1).Shapes("MonthShape1")

I didn't get the runtime error any more.

I expected to get a runtime error 13 on the line:

Set opicture = oslide1.Shapes.Item("MonthShape2")

But I was amazed I didn't!!

I did get the runtime error 13 on :

Set opicture = oslide2.Shapes.Item("MonthShape4")

So I change it to look like I had on shape 1:

Set opicture = pwpt.Slides(2).Shapes("MonthShape4")

I again stepped through my code really not knowing at all what to expect on shape 5 and surprisingly it worked.

So in the large block of code you see above is how I left it last night. But this morning I change the lines for shapes 1 and 4 to

Set opicture = oslide1.Shapes.Item("MonthShape1")
Set opicture = oslide2.Shapes.Item("MonthShape4")

And the dang thing works and I can't duplicate my error 13 I was getting last night. I learned Basic programming on a Commodore pet in the 80s and VB back in early 90s, so I know I am rusty but these problems are crazy!

Any ideas why they would be so sporadic?
 



Code:
Set objppt = CreateObject("PowerPoint.Application")
objppt.Visible = msoTrue
Set pwpt = objppt.Presentations.Open2007("c:\tdg_template.pptm")
Dim oslide1 As [b]objppt.[/b]Slide
Dim oslide2 As [b]objppt.[/b]Slide

same with EVERY OTHER POWER POINT OBJECT that you declare.

FYI, I personally would not declare x slide objects for x slides in the presentation, unless you are COMPARING multiple objects at a time. One Slide object, one picture object, etc, is sufficient in most cases.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I put objppt.slide on the dim statement and get compile error user-defined type not defined.
 


You must have a reference set for MS PowerPoint Object Library in Tools > References

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Yes I have a reference to the MS Powerpoint 12 Object library and it was checked last night, and still remains checked.

 


try
Code:
    Dim oSlide As PowerPoint.Slide
mine compiles. your OBJECT is unassigned at comile time -- late binding.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I think that was it. Last night when I dim'ed the variables I noticed there were two types of slides to select from.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top