Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Sep 2002
    Location
    Moline, Illinois, USA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Button (Access 2002)

    Hi. I've created a form where I would like to include a button. I would like this button to open a specific Excel worksheet. Is this possible? I can see the wizard for buttons allows me to "Run Excel", but how can I specify a worksheet I want opened? Thanks!

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button (Access 2002)

    Here is some code that, when placed in the click event of the button, will open Excel and the specific workbook for you.

    <pre>dim objXL as Object
    dim wbk as Object

    set objXL = CreateObject("Excel.Application")
    set wbk = objXL.Workbooks.Open("c:fullpathtoyourworkbook.xls ")

    objXL.Visible = true

    Set wbk = Nothing
    set objXL = Nothing</pre>

    This code creates a new instance of Excel, opens the Workbook you specify, makes the Excel instance visible and then releases the pointers to the Workbook and Excel Instance.

    BTW, this code does not need any references to Excel set.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    New Lounger
    Join Date
    Sep 2002
    Location
    Moline, Illinois, USA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button (Access 2002)

    Thank you!!! That was great. I'm going to study it now and see if I understand what I just pasted in. Thanks so much.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Button (Access 2002)

    Bryan's code will work fine. Just for your information, there are other possibilities - with and without coding:

    - Set the HyperlinkAddress property of the command button to the path+filename of the Excel worksheet (no coding at all), or
    - In the OnClick event of the button, use Application.FollowHyperlink followed by the path+filename as a string (surrounded by quotes), or
    - Use the Windows API function ShellExecute; search for ShellExecute in this forum for examples.

  5. #5
    New Lounger
    Join Date
    Sep 2002
    Location
    Moline, Illinois, USA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button (Access 2002)

    Thank you. I really like the hyperlink option. Thanks for your help!

Posting Permissions

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