+ Reply to Thread
Results 1 to 6 of 6

Problem with macro not working properly on excel 2007

  1. #1
    Registered User
    Join Date
    03-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    7

    Lightbulb Problem with macro not working properly on excel 2007

    Hello Forum,

    I am coming to you regarding a small problem on a macro.
    This macro is made to insert pictures in a cell automatically after double click. It resizes the pic according to heigh and width of the cell. Very usefull macro in fact :-)
    This macro works very well with excel 2003.
    Now am shifting to excel 2007 and noticed that macro still works. insertion of pictures is still happening.
    But once inserted and while sorting out the excel sheet it appears that pictures wont move.
    I hope someone has the solution to this.
    Thanks in advance

    the script is as follow and i am attaching the file as well

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Application.Dialogs(xlDialogInsertPicture).Show

    With Selection
    .ShapeRange.LockAspectRatio = msoFalse
    .Width = Target.Width
    .Height = Target.Height
    .Placement = 1
    .PrintObject = True
    End With

    End Sub

  2. #2
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Problem with macro not working properly on excel 2007

    What do you mean it won't move? You set Placement to 1 (xlMoveAndSize) and this certainly seems to work OK for me but maybe i am not doing what you are doing. Can you provide exact ciurcumstances in which you are seeing thsi not move? List the steps you go through.

  3. #3
    Registered User
    Join Date
    03-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Problem with macro not working properly on excel 2007

    here is the file i forgot to attach
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Problem with macro not working properly on excel 2007

    Hi! I have attached the file which makes it easier to understand.
    if you want to sort the data in the sheet by alphebetical order for instance, the pictures wont follow the sorting and stay where they are. thats what i meant by not moving

  5. #5
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Problem with macro not working properly on excel 2007

    Ah yes I see the problem. That's rather annoying isn't it?

    I have been unable to determine a setting or proerty to allow the pictures to Sort correctly with the data.

    I don't have xl2010 to test currently, but will give it a go later. In the meantime, I hope someone else has a solution for you.

  6. #6
    Registered User
    Join Date
    03-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Problem with macro not working properly on excel 2007

    actually i have found a solution. if the picture 's size is just a bit smaller than dimension of cell it is inserted in, then there is no problem :-) pictures get sorted as well...
    here is the macro...

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    ligne = Selection.Row

    Application.Dialogs(xlDialogInsertPicture).Show



    With Selection
    .ShapeRange.LockAspectRatio = msoFalse
    .Width = Target.Width - 3
    .Height = Target.Height - 3
    .Placement = 1
    .PrintObject = True
    End With

    End Sub


    Now am thinking of another upgrade for this macro.. i dont know if you will be able to help.

    When you double click the dialog box to insert picture appears and you need to choose path to file and file name.
    Now here is what could help.
    I keep the file name of the picture in the excel sheet itself. let say in colomn A. it s a EAN code (only number). It would be great if excel could copy what is in the corresponding cell and insert it in the dialogue box... i hope you see wat i mean... if you know how to do this you will make my day!!!
    Thanks in advance

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1