un4given1 Posted April 7, 2006 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.
IcemanND Posted April 8, 2006 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
un4given1 Posted April 8, 2006 Author Posted April 8, 2006 Thanks Iceman. This should do the trick. Good to see ya again!
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now