Reputation: 1
I have Word for Mac 2011 on a MacBook with Yosemite 10.10.5. In Word I am trying to create a macro that will insert a file named home.gif
into Word documents. home.gif
is in a directory called “List” which is a sub-directory of “Kindle” which is on my desktop (Desktop\Kindle\List).
The recorded steps are: Insert>>Photo>>Picture from file ...>>Desktop>> Kindle>>List>>home.gif>>Insert
Here is the result:
Selection.InlineShapes.AddPicture filename:= _
“/Users/macbookpro/Desktop/Kindle/List/home.gif”, LinkToFile=False._
SaveWithDocument=True
Selection.InlineShapes.AddPicture filename:=”, LinkToFile:=False, _
SaveWithDocument:=True
On another forum, I read that the hyphens should be colons, so I changed it to this:
Selection.InlineShapes.AddPicture filename:= _
“Users.macbookpro.Desktop.Kindle.List.home.gif”, LinkToFile=False._
SaveWithDocument=True
Selection.InlineShapes.AddPicture filename:=”, LinkToFile:=False, _
saveWithDocument:=True
That brought up: ““Can’t execute code in Break Mode”.
Upvotes: 0
Views: 353
Reputation:
What you need is something like
Selection.InlineShapes.AddPicture filename:= _
"Macintosh HD:Users:macbookpro:Desktop:Kindle:List:home.gif", _
LinkToFile:=False, _
SaveWithDocument:=True
"Macintosh HD" is the name of the Volume (Drive) that the file is on. Your drive could be called something else. If so, you will need to change "Macintosh HD" to that name. You can see the full path name by right-clicking on the home.gif file in Finder and clicking the Get Info option. Look at "Where", and you will see the path of the folder, but with arrows instead of colons (:)
These days Mac OS X usually prefers Unix style path anems with forward slashes. (For historical reasons, they are called "POSIX" file names in Applescript). But Microsoft Office for Mac 2011 has some quite old code in it, and not everything recognises POSIX file names. In this case, Word's macro recorder does two things wrong:
Please notice that named parameters such as filename, LinkToFile and SaveWithDocument have to be followed by ":=", not just "=". So you need
SaveWithDocument:=True
not
SaveWithDocument=True
The reason you get the message "Can’t execute code in Break Mode" is usually because you have put VBA in debug mode rather than stopping execution. When you do that, it is really waiting to continue. However, if you try to start another macro you will get that message.
Upvotes: 1