VBA Module not working in Excel 2013 nor in Mac's Excel 2011

KayWill

New Member
Joined
Jan 22, 2015
Messages
36
I'm using Excel 2010 but others in the company is running on Mac, using Excel 2011 for Mac or MS Office Excel 2013. The following code works for me with no issue :

Option Explicit


Public Sub Add_Pic()

Dim oActive As Worksheet
Dim oShape As Shape
Dim vSelection As Variant
Dim lTop As Long
Dim lLeft As Long

Set oActive = ThisWorkbook.ActiveSheet

'Allow the user to browse for an image file
vSelection = Application.GetOpenFilename("Graphics files (*.gif;*.jpg), *.gif;*.jpg")
If vSelection = False Then
MsgBox "Select a File Please!!!"
Exit Sub
End If

'Offset the top left corner of the image to be in the
'center of the selected cell
lTop = Selection.Top + (Selection.Height / 2)
lLeft = Selection.Left + (Selection.Width / 2)

'Insert the image at the fixed size 80 X 80 and then reset size to 100%
Set oShape = oActive.Shapes.AddPicture(vSelection, True, True, lLeft, lTop, 80, 80)
oShape.ScaleHeight 1, msoTrue
oShape.ScaleWidth 1, msoTrue

'Name the shape "Picture" with the cell address appended
oShape.Name = "Picture" & Selection.Address

End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim oShape As Shape
Dim sName As String

'Toggle picture visibility when the cell in which
'the picture was originally inserted is selected

sName = "Picture" & Target.Address

For Each oShape In Sh.Shapes
If oShape.Name = sName Then
If oShape.Visible = msoTrue Then
oShape.Visible = msoFalse
Else
oShape.Visible = msoTrue
End If
End If
Next
End Sub

None of my PM's or Sales team is able to utilize the sheet but others using 2010 can. If anyone can advise what I need to fix / adjust in order for this to work in MS Office 2013 Excel (majority) & for MAC users (very small group), it would be greatly appreciated
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I have fixed the issue with 2013, it appears that when I protected the sheet, it was not allowing the function to work so I unprotected the sheet and re-protected after files were embedded and works fine now. BUT, I'm still needing assistance with the MAC 2011 Excel version as it is not working at all.

Thanks,
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top