Opening Excel Spreadsheet from MSACCESS
Feb 17 2004, 06:15 AM
From: Chennai, India
To open Excel while in Access
1.Open a Database
2.Click Forms tab and open in Design View
3.Using Tool Box , place a command button control on the Form
4.Change the caption of the button to Open excel and change name to openExcel
5.Right Click the command button and select build event and select Code builder
6. In the code window write the following code
(note-.You should make a reference to Excel object library , Go to VBE by pressing Alt+F11 then click Tools > reference and then make a check mark against Microsoft Excel 9.0)
The code is as follows
Private Sub OpenExcel_Click()
'make a reference to Microsoft excel 9.0 object library
Dim AppExcel As Excel.Application
Dim wSheet As Worksheet
Dim wBook As Workbook
Set AppExcel = CreateObject("Excel.Application")
If AppExcel.Workbooks.Count = 0 Then
Debug.Print "Adding a new Workbook"
Set wBook = AppExcel.Workbooks.Add
Set wSheet = AppExcel.Sheets(1)
wSheet.Cells(2, 1).Value = "Welcome"
wSheet.Cells(3, 1).Value = "To"
wSheet.Cells(4, 1).Value = "UtterAccess"
AppExcel.Visible = True
This is adapted from Visual Basic6 Developer’s handbook written by Evangelos Petroutsos and Kevin Hough
|Go to Top · Lo-Fi Version||Time is now: 22nd May 2013 - 05:04 AM|