Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    May 2001
    Location
    Omaha, NE USA, Nebraska, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Printing Excel worksheet from Access

    In Access 97, want to know if it is possible to print an excel worksheet automatically. I have several reports that get printed on a regular basis. I have created an Access macro that is kicked off by a command button. Is there a procedure/process that I can incorporate into the macro to open excel, open a file, select the appropriate worksheet, print the active worksheet, close the file, close excel, and then return the focus to the command button that started the whole process?

    Excel resides in the following location-- "C:Program FilesMicrosoft OfficeOfficeEXCEL.EXE"

    The data file resides in the following location-- "D:My DocumentsPersonalExcelmovies.xls" and I want to print 'Sheet1'.

    Any help would be greatly appreciated.

    Thanks <img src=/S/help.gif border=0 alt=help width=23 height=15> steve69

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing Excel worksheet from Access

    Steve,
    First, be sure you have the reference to Microsoft Excel 8.0 library checked under Tools|References (from within the code window of Access). Then you can use something like the following:<pre>Sub btnExcel_Click()
    Dim XLApp as New Excel.Application
    XLApp.Workbooks.Open "D:My DocumentsPersonalExcelMovies.xls"
    XLApp.Sheets("Sheet1").PrintOut
    XLApp.Quit
    Set XLApp = Nothing
    End Sub</pre>

    You may have to tweak it a bit, but this is the general idea.

    HTH <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  3. #3
    2 Star Lounger
    Join Date
    May 2001
    Location
    Omaha, NE USA, Nebraska, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing Excel worksheet from Access

    Thank you, that worked perfectly. By the way, is there someplace to get information on the commands that are available when referencing the excel app from within Access VBA??

    steve69 <img src=/S/help.gif border=0 alt=help width=23 height=15>

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Printing Excel worksheet from Access

    The VBA Developer's Handbook (Sybex) has a lot of examples in it, but you can also get information from <A target="_blank" HREF=http://download.microsoft.com/download/office2000dev/sample/2/WIN98/EN-US/OFFAUTMN.EXE>this link</A> at Microsoft. It covers both Office 97 and Office 2000 automation.
    Charlotte

Posting Permissions

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