PC Review


Reply
Thread Tools Rate Thread

Creating Excel Macros From Access

 
 
Arkansas Lady
Guest
Posts: n/a
 
      25th Sep 2008
How to you create an Excel Macro using VBA in Access? Thank you for your
assistance.
--
Arkansas Lady
 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      26th Sep 2008
See if the following example will help you get started.

Public Sub DemoExcelFromAccess()

Dim strCurrProjPath As String 'Path of this Access database
Dim objExcel As Object 'Excel.Application
Dim objWorkbook As Object 'Excel.Workbook
Dim objWorksheet As Object 'Excel Worksheet
Dim strXlPathFileName As String 'Path and Excel filename

'Path of current Access project
strCurrProjPath = Application.CurrentProject.Path

'Assign Path and filename of XL file to variable
'Note:In this example Test Workbook.xls in same folder
strXlPathFileName = strCurrProjPath & "\" & "Test Workbook.xls"

'Assign Excel application to a variable
Set objExcel = CreateObject("Excel.Application")
'objExcel.Visible = True 'Can be visible or not visible
objExcel.Visible = False

'Open the Excel Workbook
Set objWorkbook = objExcel.Workbooks.Open(strXlPathFileName)

'Loop through worksheets in workbook
For Each objWorksheet In objWorkbook.Worksheets
MsgBox objWorksheet.Name
Next objWorksheet

Set objWorksheet = Nothing

'Close and Save the Excel workbook
objWorkbook.Close SaveChanges:=False

Set objWorkbook = Nothing

objExcel.Quit

Set objExcel = Nothing

End Sub

--
Regards,

OssieMac


"Arkansas Lady" wrote:

> How to you create an Excel Macro using VBA in Access? Thank you for your
> assistance.
> --
> Arkansas Lady

 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      26th Sep 2008
Forgot to tell you that while in the Access VBA editor, Select Tools ->
References and check the box against Microsoft Excel 10.0 Object library.
(9.0 for 2000, 10.0 for 2002, 11.0 for 2003 and 12.0 for 2007 depending on
which version you are using.) Ensure that you actually check the box. Don't
do what I did the first time and just selected the option and then wondered
why it did not work.

--
Regards,

OssieMac


"Arkansas Lady" wrote:

> How to you create an Excel Macro using VBA in Access? Thank you for your
> assistance.
> --
> Arkansas Lady

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating add-ins from Excel 4 macros =?Utf-8?B?R3JhaGFt?= Microsoft Excel Programming 8 18th Jul 2006 06:02 PM
creating excel macros =?Utf-8?B?RGljaw==?= Microsoft Excel Worksheet Functions 0 2nd Jun 2006 06:56 PM
Creating and running macros for excel in access As on click event. marleyuk Microsoft Access External Data 0 10th Mar 2006 09:20 AM
Creating and running macros for excel in access marleyuk Microsoft Access VBA Modules 0 10th Mar 2006 09:17 AM
Creating a .EXE to run excel macros Hemanth Microsoft Excel Programming 4 6th Jan 2006 06:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:45 PM.