none
How to connect the events in Excel COM component by using VBS RRS feed

  • General discussion

  • Hi, 

    i have read the documents in MSDN regarding the method wscript.createobject and also the others, such as below:

    object.CreateObject(strProgID[,strPrefix]) 
    Arguments
    object
    WScript object.
    
    strProgID
    String value indicating the programmatic identifier (ProgID) of the object you want to create.
    
    strPrefix
    Optional. String value indicating the function prefix.

    I write the code but it not work, if using the progid "internetexplorer.applicatin" instead of "excel.application", then it work well, code is here:

    on error resume next
    set objExcel=wsh.createobject("excel.application","obj_")
    if err then
    msgbox err.Description
    wscript.quit
    end if
    on error goto 0
    objExcel.visible=true
    'this line should be commented while using IE progid
    objExcel.workbooks.open  "C:\Users\Administrator\Desktop\book1.xlsx"
    
    pending = true
    while pending
        WScript.Sleep(100)
    wend
    
    'event for excel
    function obj_SheetChange(sh,target)
    WScript.Echo("You just change ")
    End function
    'event for IE
    function obj_OnQuit()
    WScript.Echo("You just quit ")
    End function

    Please help me to find the reason, thanks!

    my env: win 7 32bit Excel2007, also tested in winXP system

    best regards,


    • Edited by fr.dong Wednesday, July 3, 2019 9:00 AM
    • Changed type Bill_Stewart Thursday, September 5, 2019 9:39 PM
    • Moved by Bill_Stewart Thursday, September 5, 2019 9:40 PM Off-topic/abandoned
    Wednesday, July 3, 2019 8:58 AM

All replies

  • Do not use the line On Error Resume Next unless you understand what it does and how it works.

    Your first troubleshooting step is to remove that line of code and see what error you get.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, July 3, 2019 2:37 PM
  • Thanks for your reply, i tried as you suggested, and no any error occured.
    Thursday, July 4, 2019 12:03 PM
  • That's only a first step in troubleshooting.

    This is not a VBA or Excel programming forum, unfortunately.


    -- Bill Stewart [Bill_Stewart]

    Friday, July 5, 2019 3:50 PM