I cannot seem to update the embedded excel objects in a few slides in powerpoint. Here is my VBA code. Any help will be appreciated.
Sub PPT_Update()
Dim PPtApp As PowerPoint.Application
Dim pptPrs As PowerPoint.Presentation
Dim pptSld As PowerPoint.Slide
Dim pptSh As PowerPoint.Shape
Dim strSourceFullName As String
Dim strLinkFile As String
Dim strLinkReference As String
Dim strTemplatePath As String
Dim strThisworkbookPath As String
Dim intDelimiter As Integer
Dim varReturn As Variant
Dim intLinkCount As Integer
Dim strPPTSaveAsName As String
Dim blnNewPresentation As Boolean
Dim whatversion As String
Dim sFileName As String
Dim stringhold As Integer
Dim SlideCount As Long
Dim iCht As Integer
whatversion = Application.Version
Application.ScreenUpdating = False
'capture current file name
sFileName = "C:\ALLERGY\ALLERGY.xls"
stringhold = Len(sFileName)
sFileName = Left(sFileName, stringhold - 4)
sFileName = sFileName & ".ppt"
If Left(whatversion, 1) = "8" Then
Set PPtApp = CreateObject("Powerpoint.Application.8"
Else
Set PPtApp = CreateObject("Powerpoint.Application.10"
End If
'\ make powerpoint window visible
PPtApp.Visible = msoCTrue
'\ force switch back to make Excel window visible
Application.Visible = True
'this code will open powerpoint file by the same client name
strTemplatePath = sFileName
'\ check to see if template exists
varReturn = Dir(strTemplatePath)
If Len(varReturn) = 0 Then
'MsgBox "Powerpoint file does not exist", vbOKOnly
Else 'template is there
'\ create PPT presentation
Set pptPrs = PPtApp.Presentations.Open(Filename:=strTemplatePath, Untitled:=msoTrue)
'\ create PPT name the same as workbook but with PPT extension
strPPTSaveAsName = Sheets("cover"
.Range("B2"
.Value 'get the client name from cover sheet
strPPTSaveAsName = strPPTSaveAsName & ".ppt"
'strPPTSaveAsName = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4) & ".ppt"
'\ if this PPT presentation already exists then ask if overwrite is desired
varReturn = Dir(strPPTSaveAsName)
If Len(varReturn) > 0 Then 'ppt file already exists
pptPrs.SaveAs ThisWorkbook.Path & "\" & strPPTSaveAsName
Else
pptPrs.SaveAs ThisWorkbook.Path & "\" & strPPTSaveAsName
End If
End If
'get the original excel file with links to powerpoint
Application.StatusBar = ""
sFileName = Left(sFileName, stringhold - 4)
sFileName = sFileName & ".xls"
strThisworkbookPath = sFileName
intLinkCount = 0
Dim x As Integer
iCht = 1
For iCht = 1 To 9
If iCht = 1 Then
Set pptPrs = PPtApp.ActivePresentation
PPtApp.ActiveWindow.ViewType = ppViewSlide
Set pptSld = pptPrs.Slides(PPtApp.ActiveWindow.Selection.SlideRange.SlideIndex)
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
pptSld.Shapes.Paste.Select
PPtApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, msoTrue
ElseIf iCht = 6 Then
PPtApp.ActiveWindow.View.gotoslide Index:=6
PPtApp.ActiveWindow.View.gotoslide pptSld.SlideIndex
For i2 = 1 To PPtApp.ActiveWindow.Selection.SlideRange.Shapes.Count
If PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Type = msoEmbeddedOLEObject Then
PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Select
PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.DoVerb Index:=0
With PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.Object.Sheets("SOURCE DATA"
.Range("a3:f25"
.Value = Sheets("SLIDE1"
.Select
ActiveSheet.Range("a2:f25"
.Value
End With
Exit For
End If
Next i2
ElseIf iCht = 7 Then
PPtApp.ActiveWindow.View.gotoslide Index:=7
PPtApp.ActiveWindow.View.gotoslide pptSld.SlideIndex
For i2 = 1 To PPtApp.ActiveWindow.Selection.SlideRange.Shapes.Count
If PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Type = msoEmbeddedOLEObject Then
PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Select
PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.DoVerb Index:=0
With PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.Object.Sheets("SOURCE DATA"
.Range("a2:b40"
.Value = Sheets("SLIDE2"
.Select
ActiveSheet.Range("a2:b40"
.Value
End With
Exit For
End If
Next i2
ElseIf iCht = 8 Then
PPtApp.ActiveWindow.View.gotoslide Index:=7
PPtApp.ActiveWindow.View.gotoslide pptSld.SlideIndex
For i2 = 1 To PPtApp.ActiveWindow.Selection.SlideRange.Shapes.Count
If PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Type = msoEmbeddedOLEObject Then
PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Select
PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.DoVerb Index:=0
With PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.Object.Sheets("SOURCE DATA"
.Range("a2:b17"
.Value = Sheets("SLIDE3"
.Select
ActiveSheet.Range("a2:b17"
.Value
End With
Exit For
End If
Next i2
End If
Next iCht
DoEvents
Set pptSld = pptPrs.Slides(1) 'reset to first slide
PPtApp.ActiveWindow.View.gotoslide pptSld.SlideIndex
pptPrs.Save
pptPrs.Close
PPtApp.Quit
Application.StatusBar = False
Set PPtApp = Nothing
Set pptPrs = Nothing
Set pptSld = Nothing
Set pptSh = Nothing
Application.Visible = True
Application.CutCopyMode = False
'go back to allergy.xls
Sheets("Cover"
.Select
'rename allergy.xls to client name, save it, and close it
strPPTSaveAsName = Sheets("cover"
.Range("B2"
.Value 'get the client name from cover sheet
strPPTSaveAsName = strPPTSaveAsName & ".xls"
ActiveWorkbook.SaveAs strPPTSaveAsName
ActiveWorkbook.Close
End Sub
Michael
Sub PPT_Update()
Dim PPtApp As PowerPoint.Application
Dim pptPrs As PowerPoint.Presentation
Dim pptSld As PowerPoint.Slide
Dim pptSh As PowerPoint.Shape
Dim strSourceFullName As String
Dim strLinkFile As String
Dim strLinkReference As String
Dim strTemplatePath As String
Dim strThisworkbookPath As String
Dim intDelimiter As Integer
Dim varReturn As Variant
Dim intLinkCount As Integer
Dim strPPTSaveAsName As String
Dim blnNewPresentation As Boolean
Dim whatversion As String
Dim sFileName As String
Dim stringhold As Integer
Dim SlideCount As Long
Dim iCht As Integer
whatversion = Application.Version
Application.ScreenUpdating = False
'capture current file name
sFileName = "C:\ALLERGY\ALLERGY.xls"
stringhold = Len(sFileName)
sFileName = Left(sFileName, stringhold - 4)
sFileName = sFileName & ".ppt"
If Left(whatversion, 1) = "8" Then
Set PPtApp = CreateObject("Powerpoint.Application.8"
Else
Set PPtApp = CreateObject("Powerpoint.Application.10"
End If
'\ make powerpoint window visible
PPtApp.Visible = msoCTrue
'\ force switch back to make Excel window visible
Application.Visible = True
'this code will open powerpoint file by the same client name
strTemplatePath = sFileName
'\ check to see if template exists
varReturn = Dir(strTemplatePath)
If Len(varReturn) = 0 Then
'MsgBox "Powerpoint file does not exist", vbOKOnly
Else 'template is there
'\ create PPT presentation
Set pptPrs = PPtApp.Presentations.Open(Filename:=strTemplatePath, Untitled:=msoTrue)
'\ create PPT name the same as workbook but with PPT extension
strPPTSaveAsName = Sheets("cover"
strPPTSaveAsName = strPPTSaveAsName & ".ppt"
'strPPTSaveAsName = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4) & ".ppt"
'\ if this PPT presentation already exists then ask if overwrite is desired
varReturn = Dir(strPPTSaveAsName)
If Len(varReturn) > 0 Then 'ppt file already exists
pptPrs.SaveAs ThisWorkbook.Path & "\" & strPPTSaveAsName
Else
pptPrs.SaveAs ThisWorkbook.Path & "\" & strPPTSaveAsName
End If
End If
'get the original excel file with links to powerpoint
Application.StatusBar = ""
sFileName = Left(sFileName, stringhold - 4)
sFileName = sFileName & ".xls"
strThisworkbookPath = sFileName
intLinkCount = 0
Dim x As Integer
iCht = 1
For iCht = 1 To 9
If iCht = 1 Then
Set pptPrs = PPtApp.ActivePresentation
PPtApp.ActiveWindow.ViewType = ppViewSlide
Set pptSld = pptPrs.Slides(PPtApp.ActiveWindow.Selection.SlideRange.SlideIndex)
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
pptSld.Shapes.Paste.Select
PPtApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, msoTrue
ElseIf iCht = 6 Then
PPtApp.ActiveWindow.View.gotoslide Index:=6
PPtApp.ActiveWindow.View.gotoslide pptSld.SlideIndex
For i2 = 1 To PPtApp.ActiveWindow.Selection.SlideRange.Shapes.Count
If PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Type = msoEmbeddedOLEObject Then
PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Select
PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.DoVerb Index:=0
With PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.Object.Sheets("SOURCE DATA"
ActiveSheet.Range("a2:f25"
End With
Exit For
End If
Next i2
ElseIf iCht = 7 Then
PPtApp.ActiveWindow.View.gotoslide Index:=7
PPtApp.ActiveWindow.View.gotoslide pptSld.SlideIndex
For i2 = 1 To PPtApp.ActiveWindow.Selection.SlideRange.Shapes.Count
If PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Type = msoEmbeddedOLEObject Then
PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Select
PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.DoVerb Index:=0
With PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.Object.Sheets("SOURCE DATA"
ActiveSheet.Range("a2:b40"
End With
Exit For
End If
Next i2
ElseIf iCht = 8 Then
PPtApp.ActiveWindow.View.gotoslide Index:=7
PPtApp.ActiveWindow.View.gotoslide pptSld.SlideIndex
For i2 = 1 To PPtApp.ActiveWindow.Selection.SlideRange.Shapes.Count
If PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Type = msoEmbeddedOLEObject Then
PPtApp.ActiveWindow.Selection.SlideRange.Shapes(i2).Select
PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.DoVerb Index:=0
With PPtApp.ActiveWindow.Selection.ShapeRange.OLEFormat.Object.Sheets("SOURCE DATA"
ActiveSheet.Range("a2:b17"
End With
Exit For
End If
Next i2
End If
Next iCht
DoEvents
Set pptSld = pptPrs.Slides(1) 'reset to first slide
PPtApp.ActiveWindow.View.gotoslide pptSld.SlideIndex
pptPrs.Save
pptPrs.Close
PPtApp.Quit
Application.StatusBar = False
Set PPtApp = Nothing
Set pptPrs = Nothing
Set pptSld = Nothing
Set pptSh = Nothing
Application.Visible = True
Application.CutCopyMode = False
'go back to allergy.xls
Sheets("Cover"
'rename allergy.xls to client name, save it, and close it
strPPTSaveAsName = Sheets("cover"
strPPTSaveAsName = strPPTSaveAsName & ".xls"
ActiveWorkbook.SaveAs strPPTSaveAsName
ActiveWorkbook.Close
End Sub
Michael