PDA

View Full Version : VBA works on pc, but not on mac?!



babsiee
10-31-2012, 04:10 AM
Hi Guys,

my macro works perfectly on a pc. It's been tested and worked correct. But when I try to run it on a mac it gets an error.

Even when I try to record a new macro on my mac it gives an error.

The error is in this part of the code:
Selection.InlineShapes.AddPicture fileName:="/Users/username/logo.jpg", _
LinkToFile:=False, SaveWithDocument:=True

The runtime error says '5152'. But I'm absolutely sure that the path of the filename is correct. Even tried to do it with '/Volumes/Macintosh HD' in front of the path but still no succes.

Hope anyone has an idea why my macro won't work.
Here is the entire code:
Sub TITLE()
Application.ScreenUpdating = False
Dim Shp As Shape
With Selection.Sections(1)
Set Shp = .Headers(wdHeaderFooterFirstPage).Shapes.AddPicture _
(FileName:="/Users/username/logo.jpg", LinkToFile:=False, SaveWithDocument:=True)
With Shp
.WrapFormat.Type = wdWrapBehind
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(21)
.Left = -70
.Top = -35

End With
Set Shp = .Footers(wdHeaderFooterPrimary).Shapes.AddPicture _
(FileName:="/Users/username/logo.jpg", LinkToFile:=False, SaveWithDocument:=True)
With Shp
.WrapFormat.Type = wdWrapBehind
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(21)
.Left = -70
.Top = -124
End With
End With
Set Shp = Nothing
Application.ScreenUpdating = True
End Sub

fumei
10-31-2012, 11:52 AM
You say that:

fileName:="/Users/username/logo.jpg",

works. Really?

babsiee
11-01-2012, 02:43 AM
yes, of course for 'username' my name is being inserted.

I have recorded a macro on the mac and then when I insert an image it also gets that kind of filename-path.

I have also tried with '/Volumes/Macintosh HD' in front of the path.

Hope you have a useful tip?

dantzu
11-01-2012, 05:47 AM
babsiee,
Are you saying that you've tried with the full path and it's still not working?

babsiee
11-05-2012, 03:16 AM
Hi dantzu,
thank you for your response. Yes it's still not working!

Actually when I try to record a macro and add a picture, there is a path coming up in my recorded macro. When I use that path in my 'new' macro it doesn't work.
Actually: The macro itself doesn't even work anymore (the one I recorder). What is up with that? Hope you guys can help.

This is the code I use right now:
Sub TitleMacro()

Application.ScreenUpdating = False

Dim Shp As Shape

With Selection.Sections(1)

Set Shp = .Headers(wdHeaderFooterFirstPage).Shapes.AddPicture(fileName:="/Users/babsiee/logo.jpg", LinkToFile:=False, SaveWithDocument:=True)


With Shp

.WrapFormat.Type = wdWrapBehind

.LockAspectRatio = msoTrue

.Width = CentimetersToPoints(21)

.Left = -70

.Top = -35



End With

Set Shp = .Footers(wdHeaderFooterPrimary).Shapes.AddPicture fileName:="/Users/babsiee/logo.jpg",
LinkToFile:=False, SaveWithDocument:=True)

With Shp

.WrapFormat.Type = wdWrapBehind

.LockAspectRatio = msoTrue

.Width = CentimetersToPoints(21)

.Left = -70

.Top = -124

End With

End With

Set Shp = Nothing

Application.ScreenUpdating = True

End Sub

babsiee
11-05-2012, 03:18 AM
the error is given in this sentence:
Set Shp = .Footers(wdHeaderFooterPrimary).Shapes.AddPicture fileName:="/Users/babsiee/logo.jpg",
LinkToFile:=False, SaveWithDocument:=True)

The error says:

Compile error:
Syntax error

fumei
11-09-2012, 06:16 PM
I still find it hard to see a path working that does not have a root!

/Users/babsiee/logo.jpg

has no root folder.