Consulting

Results 1 to 4 of 4

Thread: Solved: Inserting a photo

  1. #1

    Solved: Inserting a photo

    I am trying to make some changes from excel 2007 on my PC to MAC 2011
    I was using this piece below to insert photos on my PC and want to know if this will also be compatible with MAC

    [vba]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Range("D7"), Target) Is Nothing Then
    Cancel = True ' Don't perform the standard action
    ' Your code here; Target is the cell being double-clicked
    'This will insert photos into merged cells
    Dim Pic As Excel.Picture
    Dim PicLocation As String
    Dim MyRange As Range
    PicLocation = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp), *.jpg;*.bmp", Title:="Browse to select a picture")
    If PicLocation = "False" Then Exit Sub
    Set Pic = Me.Pictures.Insert(PicLocation)
    With Pic.ShapeRange
    .Left = Target.Left
    .Top = Target.Top
    .LockAspectRatio = msoFalse
    .ZOrder msoBringForward
    If .Width > .Height Then
    .Width = Target.Width
    If .Height > Target.Height Then .Height = Target.Height
    Else
    .Height = Target.Height
    If .Width > Target.Width Then .Width = Target.Width
    End If
    End With
    With Pic
    .Placement = xlMoveAndSize
    .PrintObject = True
    End With
    End If
    End Sub
    [/vba]

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    The FileFilter arguments are handled differently on a Mac. If I want a file filter I use AppleScript rather than VBA.

    [VBA]#If Mac Then
    PicLocation = "False"
    On Error Resume Next
    PicLocation = MacScript("choose file of type ""public.jpeg"" with prompt ""Browse to select a picture"" ")
    On Error GoTo 0
    #Else
    PicLocation = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp), *.jpg;*.bmp", Title:="Browse to select a picture")
    #End If[/VBA]

  3. #3
    Will both codes work or will i need to make changes as you suggested

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    The format of the fileformat argument in post#1 will cause an error when run on a Mac. Using conditional compiling (as in post #2) will prevent that by causing the Window's style code not to be run or even compiled.

    although on closer examination this edit should be made
    [vba]PicLocation = MacScript("choose file of type {""public.jpeg"", ""public.bmp""} with prompt ...)[/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •