Bryce Bassett
asked on
Division by zero error in VBA Office 2011 for Mac, AddPicture command
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.
Sub insertgraphic()
If Application.Presentations.Count = 0 Then
MsgBox "A presentation must be open to use this command.", vbInformation
Exit Sub
End If
Call makesureslideselected
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
Hi,
pls try
currentslide.Shapes.AddPic ture fileName:=pickedgraphic, linktofile:=False, savewithdocument:=True, Left:=100, Top:=100
Regards
pls try
currentslide.Shapes.AddPic
Regards
ASKER
Rgonzo, I made the change you suggested but am still getting the same error. Any other ideas?
HuaMinChen, can you be more specific? What value do I need to change from 0 to 1? I'm not using any numeric values in this code that I know of.
Thanks
HuaMinChen, can you be more specific? What value do I need to change from 0 to 1? I'm not using any numeric values in this code that I know of.
Thanks
I don't see any way the code you have could produce that error are you sure there isn't other code you haven't mentioned.
This is not the problem but you could replace this
With
This is not the problem but you could replace this
storedgraphicfolder = GetSetting("Microsoft PowerPoint", "HPCToolbar", "storedgraphicfolder", "")
On Error GoTo 0
If storedgraphicfolder = "" Then storedgraphicfolder = "Macintosh HD:Library"
With
storedgraphicfolder = GetSetting("Microsoft PowerPoint", "HPCToolbar", "storedgraphicfolder", "Macintosh HD:Library")
which will do the same thing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Appreciate the suggestions from both experts, but neither one solved my issue. In the meantime, I came up with a solution on my own.
You need to locate the relevant place and then put one "if" statement there, to change 0 to 1.