VBA question when going from Win 2000 to XP

mtampa

Board Regular
Joined
Oct 15, 2007
Messages
61
We have a bunch of automated macro's that run on our computers at night here at work. I am not the person who built them, but simply the last person left in the office who can work with them. I just take old scripts and modify them to what I need, but am not always completely sure what I'm doing.

I'm getting the following error when I try to run my script on the XP machine:

Script: ........xyz
Line: 2
Char: 1
Error: Invalid procedure call or argument
Code: 800A0005
Source: Microsoft VBScript runtime error

It appears to me the part of my scrip the XP comp is getting upset with is the following:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ("cm")

wscript.sleep 30000

Dim oAccessApp
Dim oExcelApp

'******************************************************
'****** WINTER 2010 ROOM INVENTORY ******
'******************************************************

Set oAccessApp = CreateObject("Access.Application")
oAccessApp.automationsecurity=1
oAccessApp.visible=true
oAccessApp.OpenCurrentDatabase("\\cgassv0001\revenue\DSS\DBs\Inventory\NAInv_w10.mdb")
oAccessApp.Run ("login")
oAccessApp.Run ("collect_Info_like_winter")
oAccessApp.Quit

wscript.sleep 5000

WshShell.AppActivate("Session A")
WshShell.SendKeys("%{F4}")


It runs just fine on a Win2000 machine, but not the XP machine. Does anyone know what needs to be modified?

Thanks!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi

I could well be wrong but think you may have to amend your Environment variable on the wondows XP machine so that you have a system variable named "cm" that would point to the cm executable.

Alternatively, if you know the name and path of the executable, you could hardcode it into the script eg replace that line with:

Rich (BB code):
WshShell.Run "c:\somefolder\cm.exe"

where the code in red is your path & executable (you can probably find out what this is by checking the cm environment variable under Windows 2000. You may need to modify the above if the path & file name contains spaces.
 
Upvote 0
Hi,

Thanks to Richard's (wanted to say Sherlock Holmes' :) ) suggestions it is known now that cmd cm does not load the inventory system in working Windows 2000 machine.
This means that cm application file is not accessible as default.
And cm environment variable with PATH of inventory application folder isn't used.
So, suggested direct path in Run parameter should work.

Just want to add that you can also set the working (default) folder of inventory system application in shortcut (use right click, choose properties) of your script on XP desktop.

One more note: if waiting of 30 seconds for loading application is too long then instead of wscript.sleep 30000 you can try something like this:
Rich (BB code):
Do Until YourCheckingConditionScript
    DoEvents
Loop

Don’t ask me about YourCheckingConditionScript because nothing is known for me about your inventory application. But you can check for example the unique file presence which could be generated at complete loading of this application.

Regards,
Vladimir
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,528
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top