Consulting

Results 1 to 5 of 5

Thread: Excel 2003 Macro, no longer working in 2010

  1. #1

    Excel 2003 Macro, no longer working in 2010

    I have a macro that works perfectly in Excel 2003, however now I have been "upgraded" to Excel 2010, and my macro no longer works as it should.

    Would anyone be able to look at the code, and suggest changes to make it work in both versions please (some users are still on Excel 2003)

    Sub insertpicture()
    Dim sPicture As String, pic As Picture
     
    'Opens dialogue box to be able to search for picture to insert
     
    sPicture = Application.GetOpenFilename _
        ("Pictures (*.gif; *.jpg; *.bmp; *.tif), *.gif; *.jpg; *.bmp; *.tif", _
         , "Select Picture to Import")
     
    If sPicture = "False" Then Exit Sub
    'Resizes the picture to fit within the allotted area on the spreadsheet
     
    Set pic = ActiveSheet.Pictures.Insert(sPicture)
    With pic
        .ShapeRange.LockAspectRatio = msoFalse
        .Height = 135
        .Width = 255
        .Top = ActiveCell.Top
        .Left = ActiveCell.Left
        .Placement = xlMoveAndSize
    End With
     
    'Compresses the picture
     
    Set pic = Nothing
        Dim octl As CommandBarControl
        
        Set octl = Application.CommandBars.FindControl(ID:=6382)
        Application.SendKeys "%A%W~"
        octl.Execute
    End Sub
    The code is designed to to open a dialogue box to enable the user to select the picture they wish to add to the spreadsheet. Once selected it resizes the picture to fit a cell range. Finally it compresses the picture (our guys have a habit of trying to put 3mb pictures on this form).

    When I say it doesnt work any longer, what it appears to be doing is actually inserting a link to the picture, which looks ok on the users PC, but when it arrives in someone else's inbox, the pictures have been replaced by links.
    Last edited by MRichmond; 02-17-2014 at 07:56 AM. Reason: Additional Info

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What is control ID 6382? Does it still exist with the Ribbon?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi. have seen stg like this:
    Application.SendKeys "%(oe)~{TAB}~"
    Application.CommandBars.ExecuteMso "PicturesCompress"
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    Thanks Mancubus. I've replaced the two lines with your suggestions however now the macro wont run at all, it highlights the Name?? Any suggestions?

    XLD Control ID 6382 is the Compress Picture dialogue box, and whilst I can find it on the ribbon I'm assuming it's been replaced by the line Mancubus has supplied.

  5. #5
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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