This is a puzzle. I've written a macro to let the user simply browse for and insert a picture from a pre-determined graphic library location. Simple VBA code. Works fine until I get to the very last line below, the AddPicture command. It gives me a "Division by Zero" error, which I've never seen. The weird thing is that I can go into debug mode, copy the same line that is generating an error into my immediate window and execute it there, and it inserts the picture just fine. What else might be going on to cause the error? This is in PowerPoint for Mac 2011. Thanks for any suggestions.
If Application.Presentations.Count = 0 Then
MsgBox "A presentation must be open to use this command.", vbInformation
Dim currentslide As Slide
Dim pickedgraphic As String
Dim pickedgraphicfolder As String
Dim storedgraphicfolder As String
Set currentslide = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex)
On Error Resume Next
storedgraphicfolder = GetSetting("Microsoft PowerPoint", "HPCToolbar", "storedgraphicfolder", "")
On Error GoTo 0
If storedgraphicfolder = "" Then storedgraphicfolder = "Macintosh HD:Library"
Dim sMacScript As String
sMacScript = "set pickedgraphic to (choose file with prompt " & """Select a file to import"" default location" _
& " alias """ & storedgraphicfolder & """) as string" & vbLf & "return pickedgraphic"
pickedgraphic = MacScript(sMacScript)
currentslide.Shapes.AddPicture fileName:=pickedgraphic, linktofile:=msoFalse, savewithdocument:=msoTrue, Left:=100, Top:=100