Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default run access macro from excel pass parameter

I need run an Access macro from Excel spreadsheet and pass a paramter from a
cell of the spreadsheet.

Is it possible to have a macro to accept paramter in Access?
If yes, can I pass parameter from excel to access macro?
If yes, any example to do so?

Your information is great appreciated,
  #2   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default run access macro from excel pass parameter

The following works for me (change parameters and include full path to your db:

Dim oAccess As Object, oDB As Object
Set oAccess = CreateObject("Access.Application")
oAccess.Visible = True
oAccess.OpenCurrentDatabase "MyFullDBPathName.mdb"
oAccess.Run "MyTestMacro", "MyParameter"

HTH

"Souris" wrote:

I need run an Access macro from Excel spreadsheet and pass a paramter from a
cell of the spreadsheet.

Is it possible to have a macro to accept paramter in Access?
If yes, can I pass parameter from excel to access macro?
If yes, any example to do so?

Your information is great appreciated,

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default run access macro from excel pass parameter

Thanks for the message,
It works from Excel side, but Access macro does not recongnize the parameter
from Excel.

The Access Macro execute the same parameter no matter what Excel sends to.

any ideas?

Thanks millions,

"XP" wrote:

The following works for me (change parameters and include full path to your db:

Dim oAccess As Object, oDB As Object
Set oAccess = CreateObject("Access.Application")
oAccess.Visible = True
oAccess.OpenCurrentDatabase "MyFullDBPathName.mdb"
oAccess.Run "MyTestMacro", "MyParameter"

HTH

"Souris" wrote:

I need run an Access macro from Excel spreadsheet and pass a paramter from a
cell of the spreadsheet.

Is it possible to have a macro to accept paramter in Access?
If yes, can I pass parameter from excel to access macro?
If yes, any example to do so?

Your information is great appreciated,

  #4   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default run access macro from excel pass parameter

Not really.

Try placing a test program in Access that displays an alternate message
based on the argument passed. For example:

Sub Test(argTest)
If argTest = "Hello" Then
Msgbox "Hello"
Else
Msgbox "Goodbye"
End if
End Sub

When making a call, change the contents of your parameter to either "Hello"
or "Goodbye" and see if the correct message is displayed. If not, then
perhaps your parameter isn't being loaded correctly before the call takes
place?

HTH


"Souris" wrote:

Thanks for the message,
It works from Excel side, but Access macro does not recongnize the parameter
from Excel.

The Access Macro execute the same parameter no matter what Excel sends to.

any ideas?

Thanks millions,

"XP" wrote:

The following works for me (change parameters and include full path to your db:

Dim oAccess As Object, oDB As Object
Set oAccess = CreateObject("Access.Application")
oAccess.Visible = True
oAccess.OpenCurrentDatabase "MyFullDBPathName.mdb"
oAccess.Run "MyTestMacro", "MyParameter"

HTH

"Souris" wrote:

I need run an Access macro from Excel spreadsheet and pass a paramter from a
cell of the spreadsheet.

Is it possible to have a macro to accept paramter in Access?
If yes, can I pass parameter from excel to access macro?
If yes, any example to do so?

Your information is great appreciated,

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default run access macro from excel pass parameter

which version MS Access do you use?

I use Access 2000.
Does Ms Access 2000 support this?

Thanks again,

"XP" wrote:

Not really.

Try placing a test program in Access that displays an alternate message
based on the argument passed. For example:

Sub Test(argTest)
If argTest = "Hello" Then
Msgbox "Hello"
Else
Msgbox "Goodbye"
End if
End Sub

When making a call, change the contents of your parameter to either "Hello"
or "Goodbye" and see if the correct message is displayed. If not, then
perhaps your parameter isn't being loaded correctly before the call takes
place?

HTH


"Souris" wrote:

Thanks for the message,
It works from Excel side, but Access macro does not recongnize the parameter
from Excel.

The Access Macro execute the same parameter no matter what Excel sends to.

any ideas?

Thanks millions,

"XP" wrote:

The following works for me (change parameters and include full path to your db:

Dim oAccess As Object, oDB As Object
Set oAccess = CreateObject("Access.Application")
oAccess.Visible = True
oAccess.OpenCurrentDatabase "MyFullDBPathName.mdb"
oAccess.Run "MyTestMacro", "MyParameter"

HTH

"Souris" wrote:

I need run an Access macro from Excel spreadsheet and pass a paramter from a
cell of the spreadsheet.

Is it possible to have a macro to accept paramter in Access?
If yes, can I pass parameter from excel to access macro?
If yes, any example to do so?

Your information is great appreciated,



  #6   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default run access macro from excel pass parameter

I use 2000 at work and XP at home.

This should also work on older versions.

Did you try the msgbox test? That should really work and also help pinpoint
where the issue is...

"Souris" wrote:

which version MS Access do you use?

I use Access 2000.
Does Ms Access 2000 support this?

Thanks again,

"XP" wrote:

Not really.

Try placing a test program in Access that displays an alternate message
based on the argument passed. For example:

Sub Test(argTest)
If argTest = "Hello" Then
Msgbox "Hello"
Else
Msgbox "Goodbye"
End if
End Sub

When making a call, change the contents of your parameter to either "Hello"
or "Goodbye" and see if the correct message is displayed. If not, then
perhaps your parameter isn't being loaded correctly before the call takes
place?

HTH


"Souris" wrote:

Thanks for the message,
It works from Excel side, but Access macro does not recongnize the parameter
from Excel.

The Access Macro execute the same parameter no matter what Excel sends to.

any ideas?

Thanks millions,

"XP" wrote:

The following works for me (change parameters and include full path to your db:

Dim oAccess As Object, oDB As Object
Set oAccess = CreateObject("Access.Application")
oAccess.Visible = True
oAccess.OpenCurrentDatabase "MyFullDBPathName.mdb"
oAccess.Run "MyTestMacro", "MyParameter"

HTH

"Souris" wrote:

I need run an Access macro from Excel spreadsheet and pass a paramter from a
cell of the spreadsheet.

Is it possible to have a macro to accept paramter in Access?
If yes, can I pass parameter from excel to access macro?
If yes, any example to do so?

Your information is great appreciated,

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default run access macro from excel pass parameter

I had similar issues with trying to run Project VBA from Excel. What
you need to do is make sure the correct References are selected in
your Excel VBA compiler. Open the VBA window, click Tools
=References and then check Microsoft Access 11.0 Object Library. The
two should be able to communicate after that. Also, if you need to
run this from different computers, or have others who don't know
anything about VBA, you could program the reference in in your macro.
Chip Pearson (http://www.cpearson.com/excel/MainPage.aspx) explained
how to do this in an email:

You can certainly add a reference using VBA code. To accomplish this,
two
things must be true. First, the object library being referenced must
exist
on the target machine and must be registered with Windows in the
Registry.
For example, you can safely set a reference via code to the VBA
Extensibility Library since you can be sure that the library will
exist on
the machine. However, if you are distributing a DLL or typelib that
you
created yourself, you must put the file in an appropriate location and
then
register that file with Windows, typically by using the RegSvr32.exe
program
(or RegAsm.exe for NET components).

Next, the code that adds the reference must execute before the VBA
RunTime
decides to recompile the code. If you distribute a workbook between
machines, VBA may determine that the code should be recompiled when
the
workbook is opened, prior to the execution of Auto_Open or
Workbook_Open.
(The most common reason for a recompilation at start up is that the
workbook
was written and last compiled on a different version of Excel and/or
Windows
than the versions on which it is being presently run.) Because the
compilation takes place before the code to add the reference is
executed,
you will get compiler errors (which cannot be ignored or trapped with
an On
Error statement). The error you will get is "User-defined type not
defined". For example, if you have a line of code like

Dim V As SomeObj

and SomeObj is defined in a DLL that is not referenced, the compiler
will
complain about the SomeObj data type before the file that defines
SomeObj is
added to the references list. It is sort of a chicken and the egg
situation
- the code can't run until the reference is added, but the reference
cannot
be added until the code runs.

If you know the exact file name to be referenced, you can add a
reference
using AddFromFile. For example, the following adds a reference to the
VBA
Extensibility library.

ThisWorkbook.VBProject.References.AddFromFile _
Filename:="C:\Program Files\Common Files\Microsoft
Shared\VBA\VBA6\VBE6EXT.OLB"

However, the same DLL or typelib may reside in different locations on
different machines and operating system versions. In this case, you
can use
the GUID (Globally Unique Identifier) of the library. The GUID is
unique
to a specific typelib or DLL, and the GUID for that component will be
the
same on all machines. For example, the GUID for the Extensibility
library is
used only by that library and nothing else, and the GUID will be the
same on
every machine regardless of the operating system version and
regardless of
where in the machine that file resides.

ThisWorkbook.VBProject.References.AddFromGuid _
GUID:="{0002E157-0000-0000-C000-000000000046}", _
Major:=0, Minor:=0

By using 0s for Major and Minor, you will reference the most recent
version.
When adding a reference via GUID, VBA will search the registry for the
specified GUID and take a few jumps around the registry to find the
file
associated with the GUID.

You can use AddFromFile or AddFromGUID in the Workbook_Open event to
set the
reference when the workbook is opened. Be sure to use an On Error
statement
to ignore the error is you are attempting to add a reference that
already
exists.

If necessary, you can use what is called "Late Binding" and declare
everything that exists in the library to be referenced As Object
rather than
As WhateverObject and use the CreateObject method to create an
instance of
the root object. For example, with "Early Binding" you would access
the
Scripting RunTime's FileSystemObject with code like:

Dim OneFolder As Scripting.Folder
Dim FSO As Scripting.FileSystemObject
Set FSO = New Scripting.FileSystemObject
Set OneFolder = FSO.GetFolder("C:\Temp")
Debug.Print OneFolder.Path

This code requires a reference to the "Microsoft Scripting RunTime
Library".
Instead of relying on the reference to the Scripting Runtime, you can
use
Late Binding as shown below.

Dim OneFolder As Object
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set OneFolder = FSO.GetFolder("C:\Temp")
Debug.Print OneFolder.Path

You'll take a performance hit with late binding, since code must
execute
behind the scenes to determine what the properties of and methods an
object
supports.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group 1998 - 2008
Pearson Software Consulting, LLC
The San Diego Project Group, LLC
www.cpearson.com


Hopefully that helps you out.

Regards,
Thedude

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default run access macro from excel pass parameter

Thanks for the message,



" wrote:

I had similar issues with trying to run Project VBA from Excel. What
you need to do is make sure the correct References are selected in
your Excel VBA compiler. Open the VBA window, click Tools
=References and then check Microsoft Access 11.0 Object Library. The
two should be able to communicate after that. Also, if you need to
run this from different computers, or have others who don't know
anything about VBA, you could program the reference in in your macro.
Chip Pearson (http://www.cpearson.com/excel/MainPage.aspx) explained
how to do this in an email:

You can certainly add a reference using VBA code. To accomplish this,
two
things must be true. First, the object library being referenced must
exist
on the target machine and must be registered with Windows in the
Registry.
For example, you can safely set a reference via code to the VBA
Extensibility Library since you can be sure that the library will
exist on
the machine. However, if you are distributing a DLL or typelib that
you
created yourself, you must put the file in an appropriate location and
then
register that file with Windows, typically by using the RegSvr32.exe
program
(or RegAsm.exe for NET components).

Next, the code that adds the reference must execute before the VBA
RunTime
decides to recompile the code. If you distribute a workbook between
machines, VBA may determine that the code should be recompiled when
the
workbook is opened, prior to the execution of Auto_Open or
Workbook_Open.
(The most common reason for a recompilation at start up is that the
workbook
was written and last compiled on a different version of Excel and/or
Windows
than the versions on which it is being presently run.) Because the
compilation takes place before the code to add the reference is
executed,
you will get compiler errors (which cannot be ignored or trapped with
an On
Error statement). The error you will get is "User-defined type not
defined". For example, if you have a line of code like

Dim V As SomeObj

and SomeObj is defined in a DLL that is not referenced, the compiler
will
complain about the SomeObj data type before the file that defines
SomeObj is
added to the references list. It is sort of a chicken and the egg
situation
- the code can't run until the reference is added, but the reference
cannot
be added until the code runs.

If you know the exact file name to be referenced, you can add a
reference
using AddFromFile. For example, the following adds a reference to the
VBA
Extensibility library.

ThisWorkbook.VBProject.References.AddFromFile _
Filename:="C:\Program Files\Common Files\Microsoft
Shared\VBA\VBA6\VBE6EXT.OLB"

However, the same DLL or typelib may reside in different locations on
different machines and operating system versions. In this case, you
can use
the GUID (Globally Unique Identifier) of the library. The GUID is
unique
to a specific typelib or DLL, and the GUID for that component will be
the
same on all machines. For example, the GUID for the Extensibility
library is
used only by that library and nothing else, and the GUID will be the
same on
every machine regardless of the operating system version and
regardless of
where in the machine that file resides.

ThisWorkbook.VBProject.References.AddFromGuid _
GUID:="{0002E157-0000-0000-C000-000000000046}", _
Major:=0, Minor:=0

By using 0s for Major and Minor, you will reference the most recent
version.
When adding a reference via GUID, VBA will search the registry for the
specified GUID and take a few jumps around the registry to find the
file
associated with the GUID.

You can use AddFromFile or AddFromGUID in the Workbook_Open event to
set the
reference when the workbook is opened. Be sure to use an On Error
statement
to ignore the error is you are attempting to add a reference that
already
exists.

If necessary, you can use what is called "Late Binding" and declare
everything that exists in the library to be referenced As Object
rather than
As WhateverObject and use the CreateObject method to create an
instance of
the root object. For example, with "Early Binding" you would access
the
Scripting RunTime's FileSystemObject with code like:

Dim OneFolder As Scripting.Folder
Dim FSO As Scripting.FileSystemObject
Set FSO = New Scripting.FileSystemObject
Set OneFolder = FSO.GetFolder("C:\Temp")
Debug.Print OneFolder.Path

This code requires a reference to the "Microsoft Scripting RunTime
Library".
Instead of relying on the reference to the Scripting Runtime, you can
use
Late Binding as shown below.

Dim OneFolder As Object
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set OneFolder = FSO.GetFolder("C:\Temp")
Debug.Print OneFolder.Path

You'll take a performance hit with late binding, since code must
execute
behind the scenes to determine what the properties of and methods an
object
supports.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group 1998 - 2008
Pearson Software Consulting, LLC
The San Diego Project Group, LLC
www.cpearson.com


Hopefully that helps you out.

Regards,
Thedude


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
pass parameter to access query Bill Manville Links and Linking in Excel 4 May 1st 23 03:45 AM
Pass parameter to launch batch file with variable from excel Frank Pozzuto New Users to Excel 0 January 15th 10 06:17 PM
Pass worksheet to macro as a parameter Przemek Excel Programming 1 July 12th 05 05:50 PM
Application.OnTime -- Unable to Pass Macro with Numeric Parameter Butaambala Excel Programming 7 June 7th 05 10:55 PM
Pass Parameter to Access Query Al Excel Programming 3 April 29th 04 10:15 AM


All times are GMT +1. The time now is 11:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"