Dear all,
I'm creating a VBA macro in excel to read data from a CSV file (containing web image link) and insert it in a PPT presentation.
The code I wrote works. However if the image link is broken (eg. the image has been removed) I get a pop up warning in powerpoint and I need to click on "ok" to proceed with the execution of the macro.
I would to avoid this pop up and I used "DisplayAlerts = ppAlertsNone", but it did not work.
Here is my code, can someone help me? (I'm using office 2007)
Thanks a lot!!!
Sub PPImageImport()
I'm creating a VBA macro in excel to read data from a CSV file (containing web image link) and insert it in a PPT presentation.
The code I wrote works. However if the image link is broken (eg. the image has been removed) I get a pop up warning in powerpoint and I need to click on "ok" to proceed with the execution of the macro.
I would to avoid this pop up and I used "DisplayAlerts = ppAlertsNone", but it did not work.
Here is my code, can someone help me? (I'm using office 2007)
Thanks a lot!!!
Sub PPImageImport()
Dim strPresPath As String, strNewPresPath As String, strCSV As String
Dim oPPTApp As Powerpoint.Application
Dim oPPTShape As Powerpoint.Shape
Dim oPPTFile As Powerpoint.Presentation
Dim SlideNum As Integer
Dim oPicture As Powerpoint.Shape
Application.ScreenUpdating = False
Dim oPPTApp As Powerpoint.Application
Dim oPPTShape As Powerpoint.Shape
Dim oPPTFile As Powerpoint.Presentation
Dim SlideNum As Integer
Dim oPicture As Powerpoint.Shape
Application.ScreenUpdating = False
'some hard coded variables for this example
strPresPath = "C:\myfolder\template.pptx"
strCSV = "C:\myfolder\data.csv"
strNewPresPath = "C:\myfolder\new.pptx"
Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath, msoTrue)
SlideNum = 1
oPPTFile.Slides(SlideNum).Select
' a sub to import the csv file in an hidden worksheet. Here I have hard coded everything
' importCSV
oPPTApp.DisplayAlerts = ppAlertsNone
'this image does not exist on purpose
imgPath = "https://www.google.it/images/srpr/randomname.png"
'the powerpoint template has a shape "IMG1" used as a placeholder
Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("IMG1")
On Error GoTo CantLoadPicture1
Set oPicture = oPPTFile.Slides(SlideNum).Shapes.AddPicture(imgPath, msoFalse, msoTrue, oPPTShape.Left, oPPTShape.Top, -1, -1)
CantLoadPicture1:
On Error GoTo -1
Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath, msoTrue)
SlideNum = 1
oPPTFile.Slides(SlideNum).Select
' a sub to import the csv file in an hidden worksheet. Here I have hard coded everything
' importCSV
oPPTApp.DisplayAlerts = ppAlertsNone
'this image does not exist on purpose
imgPath = "https://www.google.it/images/srpr/randomname.png"
'the powerpoint template has a shape "IMG1" used as a placeholder
Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("IMG1")
On Error GoTo CantLoadPicture1
Set oPicture = oPPTFile.Slides(SlideNum).Shapes.AddPicture(imgPath, msoFalse, msoTrue, oPPTShape.Left, oPPTShape.Top, -1, -1)
CantLoadPicture1:
On Error GoTo -1
oPPTFile.SaveAs strNewPresPath
oPPTFile.Close
oPPTApp.Quit
Set oPPTShape = NothingoPPTFile.Close
oPPTApp.Quit
Set oPPTFile = Nothing
Set oPPTApp = Nothing
oPPTApp.DisplayAlerts = ppAlertsAll
End SuboPPTApp.DisplayAlerts = ppAlertsAll