Question

VB in Excel

Asked by: ltorres321

hello!!

I need to create a method in excel VB that runs a HTA file. What would that look like??

my file is located at

M:\MAS90\Home\MAS90.hta

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-20 at 11:43:12ID24669139
Tags

Excel

Topics

Visual Basic v1.0.5.x

,

Microsoft Excel Spreadsheet Software

,

VB Controls

Participating Experts
4
Points
500
Comments
35

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Excel with vb
    To, experts I created one table having column desc1,qty,disc,cost in "word document". From vb i open the template of this word document.And assign values to each and every column. I want to do the same thing with "excel".How can i do it ? Please explain...
  2. Vb and excel
    I have a VB App that is creating mulitple excel spreadsheet and poluating them from a recordset. At the minute this is taking up to 7 minutes which is way to long... Does anyone have any suggestions??? This is urgent!!!!
  3. VB excel
    This is my vb code to execute sql code and then send the result to a csv file; I then save it as an excel file. The problem is date fields in my csv file gets written as : DOB #1940-10-10# #1940-10-10# #1940-10-10# If I go to the excel file and delete the # , in the formula b...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: jfpiepgrassPosted on 2009-08-20 at 12:03:06ID: 25145932

I am not familiar with the hta extention, or what program you would use to open it.  I am assuming that you double click the hta file, and windows loads the appropriate program.  If you know the program, excel macros can load the program using the shell command.

shell "drive:/path/program M:\MAS90\Home\MAS90.hta"

I can help in determining the name and location of the program if you want.

 

by: ltorres321Posted on 2009-08-20 at 12:13:26ID: 25146023

I just need excel to run the file user will not be clicking on the file it will be part of code.. That will call the file and run it..

I will try what you posted looks like it makes sense i just dont know the syntax.

Thanks

 

by: ltorres321Posted on 2009-08-20 at 12:16:10ID: 25146039

No did not work..

may this would help..

excel can open a command prompt enter the path and enter and close that will work too

if Excel cant just run the file

 

by: jfpiepgrassPosted on 2009-08-20 at 13:08:50ID: 25146586

Have you determined wich program opens your hta file?

Can you post your call to the shell command?

 

by: ltorres321Posted on 2009-08-20 at 14:05:36ID: 25147130

I can call it from the command line simply typing the file name.. if i am in the folder where the file is obviously..

Thats just it I dont have any thing I want to create a VB method that runs this file..

Maybe this will help...heres the order of the process that is taking place
user presses a button in Excel
Button runs a macro that process data and saves it to an external csv file
Now macro will call a method that run HTA file...(heres where im stuck)
HTA file will start to process that csv file

I can run the hta file from the command line but how to I run the file from a macro in Excel..


I was thinking if VB can open a command window and have it run the hta file then close its self once its executed the HTA file....(Just a thought)

 

by: RobSampsonPosted on 2009-08-20 at 15:49:38ID: 25147834

A HTA file is launched by the MSHTA.exe process.

You should be able to use:
shell "mshta.exe ""M:\MAS90\Home\MAS90.hta"""

Regards,

Rob.

 

by: ltorres321Posted on 2009-08-21 at 06:20:58ID: 25151475

Hello Rob,

Yes, the method now open the file with this method

Public Sub ImportMAS90()

Shell "mshta.exe ""M:\MAS90\Home\MAS90.hta"""

End Sub


If I run it from the command line it works perfect... If I run it from the method in Excel I get an:
Error #12: File does not Exist (or already exist)
thats wierd??

 

by: jfpiepgrassPosted on 2009-08-21 at 08:48:14ID: 25153037

Have you tried.

Shell "mshta.exe M:\MAS90\Home\MAS90.hta"

 

by: ltorres321Posted on 2009-08-21 at 10:06:12ID: 25153723

Nope sorry same error...

I dont understand.. What could it be the command line it works but when excel open the file it fails with this error?

 

by: imnoriePosted on 2009-08-21 at 15:23:03ID: 25156405

Have you tried using FollowHyperlink?

I think that might work, but I've got to ask what you are doing with the hta file?

This worked for me.

ThisWorkbook.FollowHyperlink "C:\test.hta", NewWindow:=True

Though I did get a pop-up window asking me to confirm I wanted to open the file.

 

by: RobSampsonPosted on 2009-08-21 at 16:13:17ID: 25156663

OK, what about
Shell "C:\Windows\System32\mshta.exe ""M:\MAS90\Home\MAS90.hta"""

Regards,

Rob.

 

by: ltorres321Posted on 2009-08-21 at 16:40:02ID: 25156760

Nothing!!

 

by: rr_milesPosted on 2009-08-21 at 20:18:21ID: 25157264

I think it is related to the problem we had when testing. Remember the batch file worked when run from ..\home. Try this, when you recieve the error 12, type "? lwd". No quotes. The result will show the path where ProvideX is running. Then we can explore solutions.
 

 

by: ltorres321Posted on 2009-08-21 at 20:52:50ID: 25157332

Wow miles  awsome  dude I'll check soon as I get to a computer!!

 

by: RobSampsonPosted on 2009-08-22 at 03:30:57ID: 25158136

Actually, can I just confirm something.....when you get this error, is the error from Excel within the Sub, or does the HTA load, and the error is actually from within the HTA?

I have tested
Shell "mshta.exe ""M:\MAS90\Home\MAS90.hta"""

and it works fine in terms of loading the HTA.

So if the error is from within the HTA, perhaps you've got some code that refers to the working directory?  If so, try

ChDir "M:\MAS90\Home\"
Shell "mshta.exe ""M:\MAS90\Home\MAS90.hta"""

Regards,

Rob.

 

by: ltorres321Posted on 2009-08-22 at 12:41:02ID: 25159943

Rob your Correct as I posted above the HTA file works fine. I loads the login..

If I run hta from command line everything runs smooth..

If I Call the hta file from a command in excel thats when I have The issue..

RRmiles helped me with MAS90 and that error 12 is a MAS90 error.. I not on a computer now writing from phone..

I will test your command later today.. for sure!! Thank you for your assistance

 

by: rr_milesPosted on 2009-08-22 at 12:56:37ID: 25159995


Making sure you are starting from M:\mas90\home should solve the error 12 problem. You Should not need the hta. Just call it as we did in the code. .

 

by: rr_milesPosted on 2009-08-22 at 13:46:06ID: 25160186

Extra Tip: Some people like to put a button in Excel to start the VB code. I like to put it in the Workbook BefroreSave procedure. I dont like to depend on users to push buttons. I want to be sure when Excel is saved, my proceedure is run automatically.That way they should always in sync.

 

by: rr_milesPosted on 2009-08-22 at 13:46:06ID: 25160187

Extra Tip: Some people like to put a button in Excel to start the VB code. I like to put it in the Workbook BefroreSave procedure. I dont like to depend on users to push buttons. I want to be sure when Excel is saved, my proceedure is run automatically.That way they should always in sync.

 

by: ltorres321Posted on 2009-08-22 at 13:53:29ID: 25160216


Miles, The excel file is not on the same server as the MAS90 Directory.. I tried to "? lwd" but when I hit space the box closes.. And with out the space i get nothing................... Yes i do need the HTA to request a login and record whos doing the operation... The HTA file works perfect.. But that may be the issue the excel file is not in the directory..

Ok I tested the excel file in the Home directory and your correct it worked perfectly fine..

Rob I tried your command from the excel file in different directory and it still did not work.

That great but I really dont like the idea of regular users going on to the MAS90 server and getting files.. This file resides on the network but not on the mas90 server..

Is there any way where I can have the file on the network where users can get to it and it still work...

There must be a work around...

Thank to both of you for the assistance!!

 

by: rr_milesPosted on 2009-08-22 at 15:01:09ID: 25160422

Put the VIWI## file in the central network location along with the Excel file. The Vi job may run initially, but still get confused. Its worth a try anyway. It it doest not work, it is possible to write a bit of ProvideX code connected to the VI job to get to the MAS90 location. See your VI manual under Perform Logic. You wont be able to write it but you will understand what is happening. You will have to convince some kind soul to write it for you.

 

by: rr_milesPosted on 2009-08-22 at 15:01:09ID: 25160423

Put the VIWI## file in the central network location along with the Excel file. The Vi job may run initially, but still get confused. Its worth a try anyway. It it doest not work, it is possible to write a bit of ProvideX code connected to the VI job to get to the MAS90 location. See your VI manual under Perform Logic. You wont be able to write it but you will understand what is happening. You will have to convince some kind soul to write it for you.

 

by: ltorres321Posted on 2009-08-23 at 07:37:33ID: 25162777

I mean a Copy of the VIWI ## file right.. At the same path where my excel file is correct.. That's what I understood..

Worst case senario if it does not work
By any chance are you a Kind soul capable?? If I created another question??

I can test tomorrow!!

 

by: RobSampsonPosted on 2009-08-23 at 20:21:20ID: 25165433

>> RRmiles helped me with MAS90 and that error 12 is a MAS90 error

If this is the case, then the HTA file is loading when the code is run from Excel, correct? It's just that you get the Error 12 when the MAS90 command is executed?

Is this the line that you have in the HTA?
prog = pvx + "\home\pvxwin32.exe  ..\soa\startup.m4p -arg DIRECT UION "&Username&" "& strPw &" SKT VIWI00"

Maybe what is wrong here is that this path does not contain absolute paths, and therefore a file cannot be found if it is run from a different location.  What happens if you make all file reference absolute, like:
prog = pvx + "\home\pvxwin32.exe  m:\pvxwin\soa\startup.m4p -arg DIRECT UION " & Username & " " &  strPw & " SKT VIWI00"

I would assume that the pvx varialbe already holds a full path before the \home\pvxwin32.exe bit??

Regards,

Rob.

 

by: ltorres321Posted on 2009-08-23 at 21:45:42ID: 25165652

Rob I tried your new Line file. and now get the error from the command line.. Now I get error even with out excel now it gives me the same error 12

FYI
The absolute path Miles is speaking of is

M:\MAS90\Home

Are you suggesting to remove the pvx value and replace it with a full path..

I have VS2008..maybe if i can out it thru a debugger I can see whats going on with the values.. Just seem to have hit a wall here..

Thank you guys for your assistance!!

 

by: RobSampsonPosted on 2009-08-23 at 22:58:35ID: 25165849

Hi, I assume you changed this bit:
pvxwin32.exe  m:\pvxwin\soa\startup.m4p

so that it points to the proper path to startup.m4p

Perhaps though, seeing as you're not running this from the server itself, maybe the problem is that there is no client mapping (from the person that runs the Excel file) to find the file, as the program will look for the paths effectively from the client, not the server.

Is there any way you could try using UNC paths throughout, like in Excel, use:

Shell "mshta.exe ""\\server\share\MAS90\Home\MAS90.hta"""

and in the HTA, use:
\\server\share\home\pvxwin32.exe \\server\share\soa\startup.m4p -arg DIRECT UION <username> <password> SKT VIWI00

But, I'm not sure what the value is that is read from the registry.  Can you post an example of what is written in
HKLM\Software\ODBC\ODBC.INI\SOTAMAS90\Directory

Regards,

Rob.

 

by: RobSampsonPosted on 2009-08-23 at 23:02:27ID: 25165863

Oh, and to output values, I tend to just use MsgBox's....so before
objShell.Run prog, 0, True

I would put
MsgBox "About to run " & vbCrLf & prog

and you'll see the value of the variable "prog" before it is executed.

Regards,

Rob.

 

by: ltorres321Posted on 2009-08-24 at 07:32:20ID: 25168661

OK. Here more Info.. I tried the new Line you gave me and it didnt even work from the command Line..

The value of Directory for SOTAMAS90 was M:\MAS90

The Images:
There are three images
1: The Top images is the message box I get when file is ran from the command Line

2: The Middle image is the message box I get when running from Excel.. (FYI I get the error 12 message First then the Message box)

3: This is a picture of the reg at the path you requested...


I also did the UNC path from method in excel..
and the Message box was just like the previous 2..

Thank you for your patience!!!

I also changes the Code with UNC path
 
Public Sub ImportMAS90()
 
Shell "mshta.exe ""\\gssrv08\MAS90\MAS90\Home\MAS90.hta"""
 
End Sub
                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: rr_milesPosted on 2009-08-24 at 07:55:23ID: 25168923

Sorry for the delay. I took Sunday off. Put the VI job in the folder where Excel starts. The problem with this is Excel is loaded by each machine locally. Therefore this can be a network nightmare. Yes I can do the code. If the error 12 box shows you a dialogue box that offers 3 buttons, select the one that will produce a Error debugging box in ProvideX. In the lower left corner there will be a button that is labled Debug. This will get the command console that you can type in ? LWD.

 

by: ltorres321Posted on 2009-08-24 at 08:14:57ID: 25169157

Away form my desk .. I will make a copy of that job to where the excel file resides..

FYI.. The error 12 message box only has 1 option.. "OK" is the only option I get

 

by: rr_milesPosted on 2009-08-24 at 08:21:48ID: 25169238

Change the command to just Providex without the rest of the command, then type ? LWD. This will not run the VI job but should avoid the error. To exit type BYE. We may also use an INI file for ProvideX, which will keep us from putting code into the VI job
 

 

by: rr_milesPosted on 2009-08-24 at 09:09:41ID: 25169729

Put this code in your Excel proceedure before you execute your call to the VI job. It will show you where XL is running and chage folder to mas90. This is hard coded for MAS90. It can be fixed to relative for your suystem.

    Set wshell = CreateObject("WScript.Shell")
    ' display the current directory
    tdir = wshell.CurrentDirectory
    MsgBox tdir
    ' change the following line for your system.
    wshell.CurrentDirectory = "f:\mas90.430\mas90\home"
    MsgBox tdir

 

by: ltorres321Posted on 2009-08-24 at 09:40:02ID: 25170044

WOW.... That its both you guys are awesome!!!

Thank you both for your patience I will raise point split the credit...

 

by: ltorres321Posted on 2009-08-24 at 09:43:04ID: 31619756

Both Experts were great!!

 

by: RobSampsonPosted on 2009-08-24 at 14:45:09ID: 25172946

Fantastic! That was a confusing one! I'm glad we were able to fix it.  I would have thought that when I suggested this:

ChDir "M:\MAS90\Home\"
Shell "mshta.exe ""M:\MAS90\Home\MAS90.hta"""

that would fix it, but obviously, there's a difference between Excel's current directory, and the Shell's current directory....LOL! Oh well, I was close!  Thanks rr_miles for your support too!

Regards,

Rob.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...