Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Mar 2001
    Springfield, Ohio, USA
    Thanked 2 Times in 2 Posts

    OpenFileDialog (Excel 2000+)

    For those of you that open multiple files with Excel, you may have noticed that on versions since 95, the Multiselect returns the file list in a random order instead of the order selected. I am trying to fix this by replacing it with the GetOpenFileName API with a hook that intercepts the WM_NOTIFY message and keeps its own internal list of filenames. I'm having trouble getting the file name. I need to send a message to someone, somehow to get it, but I'm having trouble figuring out the details.

    OK, that's the big picture; here are the details. I started this months ago with, I believe, Hans's class wrapper for GetOpenFileName, see <post:=505,867>post 505,867</post:> and then got busy with other things.

    To that beginning, I set the OFN_ENABLEHOOK Flag and added an lpfnHook procedure. So now whenever the user changes the file selection, a WM_NOTIFY message is sent to my hook proc, but I cannot figure out how to grab the filename.

    I think that has the solution because he gets the filename in his hook procedure, but his is the most cryptic VB code that I have ever seen. His code that is pertinent is
    <pre>Function PosProc&(ByVal nCode&, ByVal wParam&, Inf As CWPSTRUCT)
    ' 11 lines of code left out
    Case &H4E 'WM_NOTIFY
    RtlMoveMemory NM, ByVal Inf.lParam, Len(NM)
    If NM.code = -12 Then
    S = String(255, Chr(0)): DoEvents
    SendMessage hw, 1125, 255, ByVal S
    S = Left(S, InStr(S, Chr(0)) - 1)
    Form1.T1 = Mid(S, InStrRev(S, "") + 1)
    Select Case LCase(Right(S, 3))
    Case "bmp", "jpg", "gif": Form1.P1.Picture = LoadPicture(S)
    End Select
    End If

    However, my code for the hook is called differently
    <pre>Public Function OFNHookProc(ByVal hWnd As Long, _
    ByVal uMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long
    ' 6 lines of code left out
    Case WM_NOTIFY
    Debug.Print " Notify"

    Do I really need the CWPSTRUCT? Can I just send a message to the hWnd in my parameter list? What is 1125? I would rather use named constants. Any clue as to the other WM_ messages that I get? Thanks for any help! The workbook is attached. --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Weert, Limburg, Netherlands
    Thanked 0 Times in 0 Posts

    Re: OpenFileDialog (Excel 2000+)

    Maybe I'm being dim, but what is wrong with sorting the Variant array returned by the GetOpenFileName function?
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    Professional Office Developers Association

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: OpenFileDialog (Excel 2000+)

    Sam wants to retrieve the files in the order they were selected by the user, not in alphabetic or similar order.

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Burwash, East Sussex, United Kingdom
    Thanked 229 Times in 210 Posts

    Re: OpenFileDialog (Excel 2000+)

    You may want to look at this page and search for CDN_SELCHANGE, which I think is the type of WM_NOTIFY message you need to be looking at.

    Microsoft MVP - Excel

Posting Permissions

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