un4given1 Posted April 7, 2006 Share Posted April 7, 2006 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 Excel2. Select a worksheet3. Enter some some data from form fields in Access4. Print the document5. Close ExcelAnyone 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. Link to comment Share on other sites More sharing options...
IcemanND Posted April 8, 2006 Share Posted April 8, 2006 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:=TrueEnd Sub Link to comment Share on other sites More sharing options...
un4given1 Posted April 8, 2006 Author Share Posted April 8, 2006 Thanks Iceman. This should do the trick. Good to see ya again! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now