PC Review


Reply
Thread Tools Rate Thread

Automating macro to run macro from Access

 
 
Cam
Guest
Posts: n/a
 
      21st Aug 2009
Hello,

I have an Excel file with several sheets of data from source in Access
macro. What is the macro code to call the macro named "CreateData" in Access
macro, then run refresh all in Excel to refresh all worksheets?
The manual way I am doing right now is:
1) Open Access file, then run the macro named "CreateData"
2) Open Excel file, then run an Excel macro called "Refresh" to refresh all
worksheets.

Would like to perform all at once in Excel. Thank you
 
Reply With Quote
 
 
 
 
Gary Brown
Guest
Posts: n/a
 
      21st Aug 2009
'/=======================================/
' Sub Purpose: run MS Access macro or procedure
' from Access in Excel
' Reference to MS Access not required - late binding
'/=======================================/
'
Public Sub CallFromMSAccess()
Dim appAccess As Object
Dim strDatabaseLocation As String

On Error GoTo err_Sub

'- - - - V A R I A B L E S - - - - - -
strDatabaseLocation = "C:\Temp\db1.mdb"
'- - - - - - - - - - - - - - - - - - -

'open an instance of Microsoft Access and a database
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strDatabaseLocation

'run an Access MACRO
appAccess.DoCmd.RunMacro "MyMacro"

'run an Access PROCEDURE
appAccess.Run "MyProcedure"

exit_Sub:
On Error Resume Next
'close Microsoft Access
appAccess.Quit
Set appAccess = Nothing
Exit Sub

err_Sub:
Debug.Print "Error: " & Err.Number & " - (" & _
Err.Description & ") - " & Now()
GoTo exit_Sub

End Sub
'/=======================================/


--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"Cam" wrote:

> Hello,
>
> I have an Excel file with several sheets of data from source in Access
> macro. What is the macro code to call the macro named "CreateData" in Access
> macro, then run refresh all in Excel to refresh all worksheets?
> The manual way I am doing right now is:
> 1) Open Access file, then run the macro named "CreateData"
> 2) Open Excel file, then run an Excel macro called "Refresh" to refresh all
> worksheets.
>
> Would like to perform all at once in Excel. Thank you

 
Reply With Quote
 
Gary Brown
Guest
Posts: n/a
 
      21st Aug 2009
Public Sub Calc_Workbook()
'calculate entire workbook - [F9]
Application.Calculate
' MsgBox "The entire workbook has been recalculated."
End Sub

--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"Cam" wrote:

> Hello,
>
> I have an Excel file with several sheets of data from source in Access
> macro. What is the macro code to call the macro named "CreateData" in Access
> macro, then run refresh all in Excel to refresh all worksheets?
> The manual way I am doing right now is:
> 1) Open Access file, then run the macro named "CreateData"
> 2) Open Excel file, then run an Excel macro called "Refresh" to refresh all
> worksheets.
>
> Would like to perform all at once in Excel. Thank you

 
Reply With Quote
 
Cam
Guest
Posts: n/a
 
      24th Aug 2009
Hello Gary,

Thanks for your help. A question I am not sure what is it in the code.

'run an Access PROCEDURE
appAccess.Run "MyProcedure"

I am not sure what procedure is it. Also your second response, what is it
function?


"Gary Brown" wrote:

> '/=======================================/
> ' Sub Purpose: run MS Access macro or procedure
> ' from Access in Excel
> ' Reference to MS Access not required - late binding
> '/=======================================/
> '
> Public Sub CallFromMSAccess()
> Dim appAccess As Object
> Dim strDatabaseLocation As String
>
> On Error GoTo err_Sub
>
> '- - - - V A R I A B L E S - - - - - -
> strDatabaseLocation = "C:\Temp\db1.mdb"
> '- - - - - - - - - - - - - - - - - - -
>
> 'open an instance of Microsoft Access and a database
> Set appAccess = CreateObject("Access.Application")
> appAccess.OpenCurrentDatabase strDatabaseLocation
>
> 'run an Access MACRO
> appAccess.DoCmd.RunMacro "MyMacro"
>
> 'run an Access PROCEDURE
> appAccess.Run "MyProcedure"
>
> exit_Sub:
> On Error Resume Next
> 'close Microsoft Access
> appAccess.Quit
> Set appAccess = Nothing
> Exit Sub
>
> err_Sub:
> Debug.Print "Error: " & Err.Number & " - (" & _
> Err.Description & ") - " & Now()
> GoTo exit_Sub
>
> End Sub
> '/=======================================/
>
>
> --
> Hope this helps.
> If it does, please click the Yes button.
> Thanks in advance for your feedback.
> Gary Brown
>
>
>
> "Cam" wrote:
>
> > Hello,
> >
> > I have an Excel file with several sheets of data from source in Access
> > macro. What is the macro code to call the macro named "CreateData" in Access
> > macro, then run refresh all in Excel to refresh all worksheets?
> > The manual way I am doing right now is:
> > 1) Open Access file, then run the macro named "CreateData"
> > 2) Open Excel file, then run an Excel macro called "Refresh" to refresh all
> > worksheets.
> >
> > Would like to perform all at once in Excel. Thank you

 
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
Help with automating macro Cam Microsoft Excel Programming 21 4th Dec 2008 09:21 PM
Automating an access 2003 macro to run when opening the database. =?Utf-8?B?S3Jpc3RpZQ==?= Microsoft Access Macros 3 11th Oct 2007 09:43 AM
Automating a macro =?Utf-8?B?R29vZHk=?= Microsoft Powerpoint 3 3rd Jul 2007 03:32 PM
Automating a Macro =?Utf-8?B?RGF2ZSBIYXdrcw==?= Microsoft Access Form Coding 8 19th May 2006 12:27 PM
Automating a Macro Reddy Microsoft Excel Misc 1 14th Oct 2003 01:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:38 PM.