Jump to content

Recommended Posts

Posted

Hey guys! It's been a LOOOOONNNNGGG time.

Anyways, I'm trying to figure out how I can program a button in Access with an On Click event that will:

1. Open a file in Excel

2. Select a worksheet

3. Enter some some data from form fields in Access

4. Print the document

5. Close Excel

Anyone have any insight into this? I have found a lot of information by doing a google search, but none of it quite fits what I'm trying to do. I can successfully do this with Word, and the coding it's very similar to what I'm seeing for Excel. Thanks for your help.


Posted

Long time no see. You should pop in more often.

Try this as a module to run from a button click:

Sub Run_Excel()
Dim appexcel As Object
Set appexcel = CreateObject("Excel.Application")
'Open Workbook, replace Devlist.xls with your filename
appexcel.workbooks.Open "devlist.xls"
appexcel.Visible = True

'Select Sheet1
appexcel.Sheets("Sheet1").Select

'repeat as needed
' Select Cell to input data into
appexcel.Range("A2").Select
' Get data from table dlookup(Value field, table, criteria)
appexcel.activecell.Value = DLookup("[ID]", "Sheet1", "[ID]=2")

'Set print area
appexcel.ActiveSheet.PageSetup.PrintArea = "$A$1:$K$2"
'Print document
appexcel.ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

End Sub

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...