Pretty much everything you do in cmd, should work somehow in PSH also.
Can't try it right now, but try passing this as "/x macroname" (with the
quotes) to the Access EXE.
Marco
--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp
PowerGadgets MVP
http://www.powergadgets.com/mvp
like i said, it opens up Access, but doesn't run the specified macro.
If you know of any good sites that show what type of script i should be
writing this is, it would be helpful. I'm a bit confused about the language
needed to code these scripts, since microsoft says it's a new language, but
all the posts i see are writing it in VB.
Well, you can use PowerShell to call your original cmd script.
I think you should be trying something like:
PSH>SOME_PATH\msaccess.exe "c:\powersource\masterupdate.mdb" "/x gr8eqlzero"
I don't want to call the original .bat file because i am working on
consolidating my scripts and programs that runs withing the old .bat files
into powershell.
My old .bat files open up my access file, run the macro, open up a software
program called "Postie" to email the results of the macro from a location and
exit out of the bat file.
That's what I'm trying to do with powershell.
"D:\Microsoft Office\Office\MSACCESS.EXE" d:\powersource\masterupdate /x
GR8EQLZERO
D:\postie\POSTIE.EXE -config -to:em...@address.com -bcc:em...@address.com
-nomsg -s:"GR8EQLZERO" -a:d:\query\GR8EQLZERO.CSV -v:2
>log:d:\query\GR8EQLZERO.txt
exit
I am a bit of a beginner with PowerShell so this may not be the best
way to do it:-
--------------------------------------------------------------------------------------------
$accessApp = new-object -com access.application
$accessApp.Application.OpenCurrentDatabase("c:\powersource
\masterupdate.mdb")
$accessApp.Application.DoCmd.RunMacro("gr8eqlzero")
$accessApp.Application.CloseCurrentDatabase()
--------------------------------------------------------------------------------------------
Alan
This worked for me:
PS C:\Program Files\Microsoft Office\Office12> ./msaccess.exe
Database1.accdb /x macro1
There's a way, I'm sure. I'm just having problems with calling the
application and passing the arguments.
Marco
Cool! Thanks for sharing.
Exception calling "RunMacro" with "1" argument(s): "The RunMacro action was
canceled." At C:\tst.ps1:5 char:38
+ $accessapp.application.DoCmd.RunAMacro< <<<< "gr8eqlzero")
Exception calling "CloseCurrentDatabase" with "0" argument(s): "The
expression you entered refers to an object that is closed or doesn't exist.
At C:\tst.ps1:7 char:44
It may depend on which version of Access you are using. I have 2002
installed on my PC.
PowerShell uses the .NET architecture.
Basically the script above creates a MS Access object ($accessApp).
It then uses standard VBA calls (Application.OpenCurrentDatabase etc)
to open the mdb file, run a macro and close the mdb file. These calls
may be different of you have an older/newer version of MS Access.
Alan
"AlanC" wrote:
> On Mar 28, 3:18 pm, Immortal_Creations <Jos...@bluestarusa.com> wrote:
> > AlanC - copied your script and now received the following error with the code
> > you provided.
> >
> > Exception calling "RunMacro" with "1" argument(s): "The RunMacro action was
> > canceled." At C:\tst.ps1:5 char:38
> > + $accessapp.application.DoCmd.RunAMacro< <<<< "gr8eqlzero")
> > Exception calling "CloseCurrentDatabase" with "0" argument(s): "The
> > expression you entered refers to an object that is closed or doesn't exist..
That might be the problem. The macro I wrote was just a simple one
that ran an SQL command to insert a record into a table. If you take
out the quit and try it again, what happens?
Alan
PowerShell is a new language, but may not have direct interfaces into
everything.
For example, it would be up to the MS Office team to add PowerShell
support to the Office Suite.
Adding PowerShell support to non-server products is likely not a current
priority.
Only the future will tell...
Marco
FTP, you have a few options, for example:
1. http://www.nsoftware.com/powershell
2. http://scriptolog.blogspot.com/2007/09/ftp-transfers-automation.html
3. ftp.exe (from DOS)
4. Using the .NET Framework classes (difficult)
#1 would also help you with your email, and there are also other
solutions also for sending SMTP mail from PowerShell.
Marco
# start Excel
$excel = New-Object -comobject Excel.Application
#open file
$FilePath = 'C:\temp\Book1.xlsm'
$workbook = $excel.Workbooks.Open($FilePath)
#make it visible (just to check what is happening)
$excel.Visible = $true
#access the Application object and run a macro
$app = $excel.Application
$app.Run("Macro1")
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
>> ----------------------- $accessApp = new-object -com
--
Immortal_creations