Solved

VB Automation2

Posted on 2007-03-23
23
165 Views
Last Modified: 2010-04-30
I have a PC where I want to use the scheduled task manager tol open up a database. When I try to use an amended vbs file there is an error message appearing that states that the system can not find the file specified even though I have confirmed its location. Plus when I use the old vbs file that opens up the excel file as a test all that happens is that an excel workbook opens up but not the file I have specified.
0
Comment
Question by:f19l
  • 12
  • 11
23 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18779440
Still using the same vbs?
Can you post this line? (or any other .run lines)

objShell.Run "C:\path to file\yourfile.xls"
0
 

Author Comment

by:f19l
ID: 18779497
Below is a copy of the code from the original vbs file which I changed so that it would open up a database:

Dim objShell:Set objShell=CreateObject("Wscript.Shell")
objShell.Run "Y:\Middle Office\DATABASE\P&L\Ldn_pl.mdb"
'may need to wait till it loads - increase the timer as necessary (millisecs)
wscript.sleep 5000
objShell.AppActivate "Window title" 'of the program's popup
objShell.SendKeys "~" 'send Enter key
Set objShell=Nothing

When I use this code to open up another databaase on my first PC it seems to work without any problems.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18779522
Is Y a mapped drive?
Is it mapped on the other system?
How is it scheduled?
0
 

Author Comment

by:f19l
ID: 18779585
Y is a mapped drive to which the PC has access to. Everyday I open the database on the PC concerned and use it without any problems. The two PCs I have are both mapped to the same drives and so there should be no problem opening up databases or spreadsheets in either one, which I can do manually. I used the original vbs file in an autotask manager scheduler on the second PC as a test to see if it would open up the file specified, it only opened up an excel workbook but not the file itself.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18779760
If you run this outside the scheduled task - does it work at all?
0
 

Author Comment

by:f19l
ID: 18779805
When I run the first vbs file that opens the spreadsheet outside the scheduler the specified file is opened but when I run the second vbs file the specified database does not open. I just get the message that the system can not find the file specified.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18779830
Let's try passing it through the command interpreter...change this line:

objShell.Run "cmd /c Start Y:\Middle Office\DATABASE\P&L\Ldn_pl.mdb"
0
 

Author Comment

by:f19l
ID: 18780005
When I do that I get the message: Cannot find the file 'Y:\Middle (or one of its components). Make sure that the path and file name are correct and that all required libraries are available. It looks like it is having problems recognising the folder "Middle Office"; the space inbetween could be causing problems.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18780023
yep..the space..
try:

objShell.Run "cmd /c Start " & chr(34) & Y:\Middle Office\DATABASE\P&L\Ldn_pl.mdb" & chr(34)
0
 

Author Comment

by:f19l
ID: 18780075
An error message appears as follows:
Script: y:\Public\Software and Info\MidasAutoload.vbs
Line:2
Char: 44
Error: Expected Statement
Code: 800A0400
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18780109
I missed a quote...sorry...

Dim objShell:Set objShell=CreateObject("Wscript.Shell")
sRun="cmd /c Start " & chr(34) & "Y:\Middle Office\DATABASE\P&L\Ldn_pl.mdb" & chr(34)
objShell.Run sRun
wscript.sleep 5000
objShell.AppActivate "Window title" 'of the program's popup
objShell.SendKeys "~" 'send Enter key
Set objShell=Nothing
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:f19l
ID: 18780180
A black screen appears with the header Y:\Middle Office\DATABASE|P&L|Ldn_pl.mdb followed by two lines of Y:\Public\Software and info>
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18780271
Change this line...

sRun="cmd /k Start " & chr(34) & chr(34) & chr(34) & "Y:\Middle Office\DATABASE\P&L\Ldn_pl.mdb" & chr(34)


the /k will leave the window open after processing for better diagnosis...
0
 

Author Comment

by:f19l
ID: 18780323
I have done that but still the same situation but with an additional black screen titled C:\WINNT\system32\cmd.exe and only one line of Y:\Public\Software and info>
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18780375
Sorry for the back-and-forth here...not sure why it's failing, but try it with this version...

sRun="cmd /k Start msaccess " & chr(34) & "Y:\Middle Office\DATABASE\P&L\Ldn_pl.mdb" & chr(34)
0
 

Author Comment

by:f19l
ID: 18780396
It works now! Thanks.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18780408
Happy to help - thanx for the grade!! :^)
0
 

Author Comment

by:f19l
ID: 18780420
You deserved it.
0
 

Author Comment

by:f19l
ID: 18780799
Sirbounty,

One final question in relation to the task manager, what line of code do I need to add so that I can open an excel file say with out the message appearing asking me whether I want to enable macros? I can put this into another separate question if you wish?

f19l.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18780919
No need...I can tell you, unless you're willing to compromise security, or digitally sign your macros, you won't get around this 'feature'... : (

Sorry about that...
0
 

Author Comment

by:f19l
ID: 18780982
How do I go about digitally signing the macros?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18781103
0
 

Author Comment

by:f19l
ID: 18781143
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now