Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting references on the fly (Office XP)

    I'm writing an application (it happens to be in Access) that's going to be distributed to a number of people, who between them differing versions of Office. I want to use the FileDialog property, which is stored in the Office object library (MSO.DLL). Because I don't know which version of Office each user has, I want to set the reference programatically, which I do using this line of code:
    <div style="width: 100%; background-color: #FFFFFF;">Set R = References.AddFromFile("C:Program FilesCommon FilesMicrosoft SharedOffice" & Int(Application.Version) & "MSO.DLL")
    DoEvents</div hiblock>
    This works fine in terms of adding the reference (it appears in the References dialogue box), but the FileDialog property still fails.
    <div style="width: 100%; background-color: #FFFFFF;">Error number:-2147467259
    Error description: "Method 'FileDialog' of object '_Application' failed"</div hiblock>

    What am I missing?
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

  2. #2
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Solved

    Ok, I've found a work-around (by reading some other threads on the same subject). By adding the reference in a seperate procedure in a different module, and running that Sub earlier, it seems to work. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

    I'm slightly baffled as to why it doesn't work if the reference is set in the same procedure, but that's academic.
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Setting references on the fly (Office XP)

    I think FileDialog was new to Office XP, so if you are supporting Office 2000 users as well, you might need to fall back on the native application dialogs.

  4. #4
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting references on the fly (Office XP)

    Yikes! Thanks for that - I've got a feeling some of them are running older versions of Office - I'll make sure I check before distributing.
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting references on the fly (Office XP)

    I do not recall which versions of Office support FileDialog. but depending on what you are trying to do, you could use API functions such as GetOpenFileName.

  6. #6
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting references on the fly (Office XP)

    Thanks, Howard. I've done almost exactly that, but not quite. Another part of my application requires a reference to the Excel object library, and Excel contains GetOpenFileName, so I've used that instead of the Office FileDialog property. GetOpenFileName was part of Excel in Office 97 (and possibly before then), and none of my clients will be running earlier versions of Office than that, so the Excel reference should be all I need.

    I hadn't thought of using API - I must remember that that's an option in the future! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting references on the fly (Office XP)

    API calls execute much faster.

Posting Permissions

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