vbScript to JavaScript

Hello Everyone,
  How can i recreate the following to JavaScript:

    <script language="vbscript" type="text/vbscript">
        sub cmdEnter_onclick()
            dim dValue
            dim objExcel
            dim objPhonebook
            dim dWindowState
            dWindowState = -4143
            set objExcel = createobject("Excel.Application")
            objExcel.Workbooks.Open "C:\dPath\D-Assistant.xls", False, , , "password"
            lstRow = objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5000").End(3).Row
            dValue = document.form1.txtEntry.value & "*"
            objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5:A" & lstRow).AutoFilter 1, dValue, , , False
            document.form1.txtEntry.value = ""
            objExcel.WindowState = dWindowState
            objExcel.Height = 400
            objExcel.Width = 768
            objExcel.Top = 318
            objExcel.Left = 2.5
            objExcel.visible = true
            objExcel.ActivateMicrosoftApp
        end sub
    </script>

thnx in advance
tony_813
LVL 9
tony_813Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

knightEknightCommented:
Because of the Excel stuff it's hard to know for sure if this will work without trying it (odds are it won't the first time)


    <script language="javascript">
      function cmdEnter_onclick()
      {
            // var objPhonebook;  //  not used
            var dWindowState = -4143;
            var objExcel = createobject("Excel.Application");

            objExcel.Workbooks.Open( "C:\dPath\D-Assistant.xls", false, null, null, "password" );
            lstRow = objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5000").End(3).Row
            var dValue = document.form1.txtEntry.value + "*";
            objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5:A" & lstRow).AutoFilter( 1, dValue, null, null, false );
            document.form1.txtEntry.value = "";
            objExcel.WindowState = dWindowState;
            objExcel.Height = 400;
            objExcel.Width = 768;
            objExcel.Top = 318;
            objExcel.Left = 2.5;
            objExcel.visible = true;
            objExcel.ActivateMicrosoftApp();

      }

    </script>
0
knightEknightCommented:
... this is because I don't know what the exact property and method names are on the Excel.Application object.  For example, it may be necessary to lower-case many of the properties for javascript:

            objExcel.height = 400;
            objExcel.width = 768;
            objExcel.top = 318;
            objExcel.left = 2.5;
            objExcel.visible = true;
0
knightEknightCommented:
... and here's one I missed that I should have known:

            var objExcel = CreateObject("Excel.Application");

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

knightEknightCommented:
oops!  I meant:

   var objExcel = new ActiveXObject("Excel.Application");
0
knightEknightCommented:
and I don't know about this one either ... if it is a method it needs parens at the end:

            lstRow = objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5000").End(3).Row()
0
knightEknightCommented:
putting it all together now ... give this a try:


    <script language="javascript">
      function cmdEnter_onclick()
      {
            var dWindowState = -4143;
            var objExcel = new ActiveXObject("Excel.Application");
// note the double-slashes below:
            objExcel.Workbooks.Open( "C:\\dPath\\D-Assistant.xls", false, null, null, "password" );
            lstRow = objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5000").End(3).Row();
            var dValue = document.form1.txtEntry.value + "*";
            objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5:A" & lstRow).AutoFilter( 1, dValue, null, null, false );
            document.form1.txtEntry.value = "";
            objExcel.WindowState = dWindowState;
            objExcel.height = 400;
            objExcel.width = 768;
            objExcel.top = 318;
            objExcel.left = 2.5;
            objExcel.visible = true;
            objExcel.ActivateMicrosoftApp();
      }
</script>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tony_813Author Commented:
Hello,
   thank you for your quick response...
   your in the right path....
   excel is starting up.... but is not opening the workbook...
   Let me watch Sopranos.. and I'll be back to play with it...

thnx
tony_813
0
knightEknightCommented:
note that you must double-slash the path to your workbook (see above)
0
tony_813Author Commented:
Hello....
   I have the following... but i'm still not able to get the workbook to open..

      function cmdEnter_onclick()
      {
            var dWindowState = -4143;
            var objExcel = new ActiveXObject("Excel.Application");

            objExcel.Workbooks.Open("C:\\Documents and Settings\\Tony\\Desktop\\HTML\\D-Assistant.xls", false, null, null, "password");
            var lstRow = objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5000").End(3).Row();
            var dValue = document.form1.txtEntry.value + "*";
            objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5:A" + lstRow).AutoFilter( 1, dValue, null, null, false );
            document.form1.txtEntry.value = "";
            objExcel.WindowState = dWindowState;
            objExcel.Height = 400;
            objExcel.Width = 768;
            objExcel.Top = 318;
            objExcel.Left = 2.5;
            objExcel.Visible = true;
            objExcel.ActivateMicrosoftApp();

      }

hmmmmmm....
I checked the password to make sure is right.. and it is...
any other ideas on what could be wrong?
0
tony_813Author Commented:
ok ok... I made the following adjustment... and it turns out that the code will open the workbook..
but there must be something else wrong...
let me play with it some more...
0
tony_813Author Commented:
ok got it to work...
it had to do with the following line... on where it was located...
apperently for JavaScript..... we have to make the application visible before anything can work...
other minor adjustments.... however, works great.. and its what I was looking for....
thnx
      function cmdEnter_onclick()
      {
            var dWindowState = -4143;
            var objExcel = new ActiveXObject("Excel.Application");
            objExcel.Visible = true;
            objExcel.Workbooks.Open("C:\\Documents and Settings\\Tony\\Desktop\\HTML\\D-Assistant.xls", false, null, null, "password");
            var lstRow = objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5000").End(3).Row;
            alert(lstRow)
            var dValue = document.form1.txtEntry.value + "*";
            objExcel.Workbooks("D-Assistant").Worksheets("List").Range("A5:A" + lstRow).AutoFilter( 1, dValue, null, null, false );
            document.form1.txtEntry.value = "";
            objExcel.WindowState = dWindowState;
            objExcel.Height = 400;
            objExcel.Width = 768;
            objExcel.Top = 318;
            objExcel.Left = 2.5;
            objExcel.ActivateMicrosoftApp();

      }
0
knightEknightCommented:
great!  the only thing I'm unsure about is the last line ...

   objExcel.ActivateMicrosoftApp();

apparently it takes a numeric parameter -- but I can't find anything on what it means.  But if it works for you as is then maybe we shouldn't fix what isn't broke.  :)
0
tony_813Author Commented:
ohhh
that last line i meant to remove...
from the Excel Application you can use the ActivateMicrosoftApp method to activate one of the following
MS Applications:

xlMicrosoftWord
xlMicrosoftPowerPoint
xlMicrosoftMail
xlMicrosoftAccess
xlMicrosoftFoxPro
xlMicrosoftProject
xlMicrosoftSchedulePlus

If the application is already running, this method activates the running application. If the application isn't running, this method starts a new instance of the application.

The same as using:

GetObject or CreateObject

tony_813
0
knightEknightCommented:
I see now ... the list may actually be longer than that.  I was playing around with it and discovered that passing in a 1 opens FoxPro (or attempts to) and passing in a -1 opens Solitare!  I didn't feel like traversing thru all possible integers, but maybe the next time I'm really really bored ...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.