Consulting

Results 1 to 6 of 6

Thread: How do I Drag and Drop to a Userform Control?

  1. #1
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,745
    Location

    How do I Drag and Drop to a Userform Control?

    I have a Userform with an Image Control on it (at least that's what I'm using right now) that opens vbModeless by a Workbook_Open.

    I'm trying to figure out how to allow the user to Drag a file to the Image and Drop it there so that a Sub can process it. I'd really want it so that the file has to be dropped on the Image control.

    Right now a command button opens a GetOpenFilename, the user gets the filename, and a Sub processes it. I was trying to polish that up a bit.

    If I can get the file name I can pass it to the current Sub. If I get the file itself as an object, I can work with that also.


    Paul

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    By "drag a file..and drop it", do you mean drag the file's icon?

    If so, where from where would the user drag the icon? The GetOpenFileName dialog box, the desktop or ???

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,745
    Location
    The most common way I've seen would be that

    1. the user has saved the file to their desktop.
    2. the user opens the WB
    3. the Userform Shows
    4. the user then drags the file from their Desktop and drops it on the image control on the userform (what I'd like to do since it think it is more intuitive)
    5. This gets a little fuzzy here, since it depends on what is available after the drag and drop, but the filename or the file itself is then handled/processed by existing VBA.

    Thanks for any ideas

    HTH

    Paul

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    This might be possible using Windows API's (about which this Mac user knows little).

    My (limited) experience with Windows machines is that the common method of selecting file, is to choose from a list (similar to GetOpenFileName's dialog). Attaching files in Outlook. Dragging icons is only used for arranging folders.

    My thought is that drag/drop may be more intuative, but it goes contrary to the user's "training" (though their other programs) that selecting a file is done by selecting from a list and pressing "OK".

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,745
    Location
    I thought that I could use the BeforeDropOrPaste, but I can't figure out if it's what I'm lookin for, or how to use it


    [VBA]

    Private Sub Image1_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean, _
    ByVal Action As MSForms.fmAction, _
    ByVal Data As MSForms.DataObject, _
    ByVal X As Single, ByVal Y As Single, _
    ByVal Effect As MSForms.ReturnEffect, _
    ByVal Shift As Integer)
    MsgBox "Here"


    Stop

    End Sub

    [/VBA]

    Paul

  6. #6
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    The first question is how to "grab" the icon from the desktop.

    or, to be more detailed, how to get the filepath of the file whose icon is under the mouse when the button is pressed.

    Then,
    how to put the filepath into your routine when the button is raised while pointing at your image.

    The difficulty that I see, (analogizing from my Mac) is that if you click on the desktop, focus is passed to the file handler portion of Windows (the Finder in Mac terms). At that point, your Excel VBA code is ignored and control passes to Windows.

    If a Windows savy person could comment, they might see a way around this, but I don't see any way to do it, even on my Mac. And I wouldn't trust the stability of the result.

Posting Permissions

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