Start Excel and get workbook handle

Hi,
I would like to build a launcher which would start Excel 2013, and then register my xll file using "RegisterXLL".
One of my prototypes is starting the process, using the path to Excel.exe, and then it gets the window handle (the ultimate goal is to reach the COM application object in order to invoke RegisterXLL).
Thus I must find the child window whose name is "EXCEL7". I can get the main window handle from the process I have created, that's fine. But in order to get the child handle, I have tried 2 functions : EnumChildWindows and FindWindowExA,
which both are part of "user32.dll".
Unfortunately, I have to wait for a certain amount of time before calling these functions, otherwise they don't work. Basically, I wait for 1 or 2 seconds, then I call EnumChildWindows or FindWindowExA, and it works fine.
But if I don't wait, then EnumChildWindows does not enumerate anything, and FindWindowExA return 0. And once I have called one of them, I can retry even 10 seconds later, they will still not work.
Then I have no idea what I must wait for, or how long I must wait.
I would gratefully appreciate some help !
Thanks
Ron

Going back to my first approach using Windows apis, I noticed that if I refresh the process after a while, then I get a different value for the MainWindowHandle. From that value, I can do the work. 
Then here is my final solution :
1) Get the MainWindowHandle
2) Enumerate the child windows (using FindWindowExA or EnumChildWindows)
3) If the child window called "EXCEL7" is not found then refresh the process and go to 1). If the window was found then continue.
It works !
ProcessStartInfo info = new ProcessStartInfo(excelPath, "/x")
UseShellExecute = false,
CreateNoWindow = true
Process process = new Process
StartInfo = info
process.Start();
IntPtr hWndChild = IntPtr.Zero;
do
process.WaitForInputIdle();
StringBuilder cname = new StringBuilder(256);
EnumChildWindows(process.MainWindowHandle, delegate(IntPtr hWndEnum, IntPtr param)
GetClassNameW(hWndEnum, cname, cname.Capacity);
if (cname.ToString() == "EXCEL7")
hWndChild = hWndEnum;
return false;
return true;
}, IntPtr.Zero);
if (hWndChild == IntPtr.Zero)
Thread.Sleep(100);
process.Refresh();
} while (hWndChild == IntPtr.Zero);
IntPtr pUnk = IntPtr.Zero;
int hr = AccessibleObjectFromWindow(hWndChild, OBJID_NATIVEOM, IID_IDispatchBytes, ref pUnk);
if (hr >= 0)
dynamic obj = Marshal.GetObjectForIUnknown(pUnk);
dynamic app = obj.Application;
app.RegisterXLL(xllPath);

Similar Messages

  • Ghost Excel workbook opens each time I start excel and prevents formulas - tried all suggested solutions without luck

    Hi
    When I start excel and open any workbook a 'ghost' work book opens it doesn't contain cells and is just greyed out. When I am working on a document whenever I start to write a formula the ghost wbook opens and I cannot see the original document to complete
    the formula. If I open multiple workbooks I sometimes get a ghost workbook for each doc that is open - after a while I get error message to say not enough reources to do even simple tasks like save work or open a document.
    I have posted on several forums and tried all suggested solutions without luck - this is really preventing me from using excel which I need daily. Personally though I am only intermediate user I think it may have something to do with a workbook that I downloaded
    that had macros in it but I cant be sure
    Any help greatly appreciated
    Thanks
    Dave

    Hi Dave,
    First make sure have installed the latest update. Second, we can repair Office 2013 from Control Panel > Programs and Features. Third, open Excel 2013 in safe mode, if it works fine, disable some 3rd-party application add-ins.
    Could you please share a screenshot of this “ghost” workbook and upload it to OneDrive? I’ll analyze it in detail as soon as accessing it.
    If there is anything about this issue, don’t hesitate to tell me.
    Best regards,
    Greta Ge 
    TechNet Community Support
    It's recommended to download and install Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support
    teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office programs.

  • Njawin and getting a handle to IE popup windows

    I am using njawin to generate mshtml and shdocvw in order to control Internet
    Explorer. I can get IE to come up and I can click links, set inputs, etc. But when I click a link the pops up a new window how do I get a handle to it? I am using the event NewWindow2 which gets called, but there is no reference to the new window passed in.
    Njawin generated Java:
    public void NewWindow2(Object o, ObjectRef objectRef, ObjectRef objectRef1) throws COMException
    MSHTML interface:
    void NewWindow2(
    IDispatch **&ppDisp,
    VARIANT_BOOL *&Cancel
    Please advise� thanks,
    Brian

    I little more info on this one...
    public void NewWindow2(Object o, ObjectRef objectRef, ObjectRef objectRef1) throws COMException
    When the NewWindow2 event is called, a reference to the original parent IWebBrowser2 is passed in the first parameter "Object o". And it looks like the new popup IWebBrowser2 should be passed in the second parameter "ObjectRef objectRef", but unfortunately it's getRef method returns null. The third parameter returns boolean which is correct according to the mshtml interface definition.
    Does the code njawin generate not support these types of events properly? What can I do to make it work?
    Thanks,
    Brian

  • Is a macbook air okay for a music producer starting out and can it handle it ? :]

    Hey Im a 16 year old beginner music producer and am getting a macbook air and was wondering if it will be able to handle logic and me recording as i rap as well?
    I know ideally a macbook pro would be best but as I'm in a certain price range I just can't afford it. I would need my mba for college for creating music instrumentals and recording, also homework ? ? ? any knowledge on this please reply ASAP, thank you.

    You can look at Refurbished MBPs as well - http://store.apple.com/us/browse/home/specialdeals/mac (if your are in another country, you can look at that country's specific store).

  • Trying to start dbconsole  and getting system error 5

    Hello,
    I am trying to launch the db console and it denie access saying 'System Error 5 has occured"
    Do anyone know what this means?
    Thanks,
    Peter

    user9174181 wrote:
    That is what I entered before I got the error message.
    First I set the sid as follows:
    "set oracle_sid=opc11g"
    which didnt give any error messages
    I then entered
    "emctl start dbconsole"
    that is the point at which I got the error message.Please copy and paste your entire session .. your actual commands and the FULL actual response. There should be a lot more returned to you than simply "error 5".
    And what edition of Vista? No oracle product is certified on any "home" version.

  • How do I backup my iPhone to iCloud and restore backup to my iPad? My intention is to restore default settings to my iPad to start over and get it synced back up with my iPhone and not loose the apps on my iPad that are for iPad only.

    I hope I am making sense to you. Thank you very much.

    1) ensure iTunes is authorized for your iTunes store account(s)
    2) connect your device and right-click or control-click it in the iTunes Source list, then choose transfer purchases from the shortcut menu that appears.
    3) sync the device
    iTunes will wipe the iPhone but, since you transferred your purchases in the previous step, your content will be in your library and you can re-populate the iPhone with it.
    above works for purchases from the iTunes store. for everything else, check out this post by Zevoneer.

  • HT4557 Selecting a shared library starts connecting and gets to what looks to be 50% of the time circle and stops without connecting to the shared library..... Has anyone experience this before and knows how to overcome it?

    I have an iphone 5 with the current operating system and an up to date itunes as of 01.04.13. The strange thing about this problem is that I have the "remote" app also installed and the Iphone can access the shared library and control what is played on itunes on the PC but not the other way around. What I want to do is play from my library through my Iphone but it is not connecting through the music application???

    Many of your points are totally legitimate.
    This one, however, is not:
    …To put it another way, the design of the site seems to be geared much more towards its regular users than those the site is supposedly trying to "help"…
    The design and management of the forums for more than five years have driven literally dozens of the most valuable contributors and "regulars" away from the forums—permanently.
    The only conclusion a prudent, reasonable person can draw from this state of affairs is that Adobe consciously and deliberately want to kill these forums by attrition—without a the PR hit they would otherwise take if they suddenly just shut them down.

  • Can't open excel and get the message

    'The file could not be accessed and the program crashes.  Any thoughts?

    The application may be corrupt. Un-install and re-install Office.
    Office 2011 Removal
    Office 2011 Removal (2)

  • Sometimes i try to start firefox and get a message. Firefox is already running. No windows are opened. I have read all the support artickle, did everything recommended. It was useless. Please write what can I do.

    The useless support article is https://support.mozilla.com/en-US/kb/Firefox+is+already+running+but+is+not+responding?s=running&as=s

    See:
    * [[Firefox is already running but is not responding]]
    * http://kb.mozillazine.org/Profile_in_use

  • Only my Les Paul sparks and gets distorted at clean input

    Hi everyone,
    I have  problem with the input levels on my M-Audio Fasttrac pro and my Gibson Les Paul (burst bucker pro pickups). Its completely impossible to play the LP through the M-Audio, and it seems like the levels on the input is too high or the pickups are too "hot". When i turn my volume knob a millimeter for 0, it starts sparkling and gets distorted, and it sounds like everything is going to crack up. This is without any plugins or filter, just my guitar through the m-audio and into my mac with Logic Express. The weird thing is, this doesn't happen with any other electric guitar I've plugged in.
    Maybe this post is more guitar technical topic, but i hope someone here could give me some tips on how to adjust the input / set up the divice so that it can handle the signal and make it playable.
    Best regards
    Mats, Norway.

    LOL!
    A $4,000 guitar for a $17 dollar app (approx. after you devide the cost by # of apps in iLife).
    Looks sweet though.
    Thanks Hang
    X

  • Workflow for exporting xml from Excel and importing into table in InDesign

    Hello,
    I have worked out how to get data from a .xlsx into a table in InDesign. However, the workflow is still a little clunky and I am looking for way to automate the process further. My current workflow is as follows (files can be download here: http://visual360.co.uk/xml.zip)
    xml is exported from .xlsx by mapping the schema (see what_I_get.xml)
    assign tags to table and individual cells in InDesign
    This is the clunky bit: edit the what_I_get.xml to:
    remove the indentation (this seems necessary as otherwise when I get to stage 4, all the imported text is also indented)
    add tag for table in InDesign (p10_table)
    add tags for individual cells (p10_c11 etc.)
    import the produced what_I_want.xml in the structure panel of InDesign.
    Can anyone point me in the direction of how to automate step 3 above?
    Thanks in advance,
    Nick

    Hi Mike,
    Thanks very much for the reply. I am not at all familiar with XSL/XSLT. I have given it a quick google and it seems like it could be quite a steep learning curve to master. Maybe if I explain the whole context here, it may allow you to point me in the direction of a tutorial that provides a step by step approach to achieve my final goal. Alternatively, you may be able to suggest a whole new workflow.
    I am in the process of updating this document: http://www.ncl.ac.uk/students/insessional/assets/documents/IS_Brochure_2014-15.pdf
    The tables on pages 10-21 contain lots and lots of repeated information. We want the layout to in this format so that each group of students has all the information relevant to them on a single double spread. However, the challenge of using this approach is that it is very high maintenance to ensure the duplicated information is kept in sync - even using a copy / paste approach.
    I was hoping to overcome this by using a single source of data (eg. a spreadsheet) which would then feed into the InDesign. This workflow seems to be overcomplicated by the apparent need to use xml as the "middle-man".
    Ideally, I would like to press the export button in Excel and get this information into the the correct cells in the tables on pages 10-21 without a significant amount of manual labour - after all, my reasons for investigating an automated approach in the first place was to avoid the manual entering of data ie. the scope for error...
    An alternative approach maybe to skip Excel altogether and just use .xml. However, I am not sure that this is possible as Indesign only seems to allow you to import each element once. Maybe you could correct me here...
    I am happy to invest a certain amount of time in developing this approach as once it is in place, it will save a huge of proof-reading time year after year, especially as inconsistencies still persist despite our best efforts to weed them out.
    If you could let me know your thoughts on this and maybe identify a tutorial that would help me, I would be extremely grateful.
    Thanks again!
    Nick

  • Itunes wont startup and getting exception errors

    So, here I am with my brand spanking new ipod touch 4 gen and very excited, that is until.... I realise something's wrong, very wrong.
    I download the new version of itunes ontop of my old version, and try to start itunes and get this error:
    "The exception unkinown software exception (0xc0000409) occured in the application at location 0x01aa3335", so I tried the below and still get the same error:
    * uninstalling anything itunes related & reinstalling
    * uninstalling anything itunes related using Revouninstaller & reinstalling
    * deleted temp drive (as per support page)
    * reconfigured using msconfig (as per support page)
    * cleared my recycle bin and rebooted machine numerous times
    I need help and don't know what I should do next..... anyone?

    Can you reinstall iTunes and then post your diagnostics for us please?
    In iTunes, go "Help > Run Diagnostics". Uncheck the boxes other than DVD/CD tests, as per the following screenshot:
    ... and click "Next".
    When you get through to the final screen:
    ... click the "Copy to Clipboard" button and paste the diagnostics into a reply here.

  • Intel Core Duo, very slow start up and doesnt recognize airport

    Hi,
    I just got upgraded to a 2GHz Intel Core Duo (10.4.7) by Apple, after they couldn't fix my iMac G5 iSight. But ever since I got it, on the initial start up every morning, it doesn't start up right away. When I press the power button, the sleep light dims on a little, stays on for about 30 seconds (with a blank screen) then the computer will eventually start up (Much much slower than normal)
    Once it finished starting up, and gets to my desktop, my airport icon doesn't show up, and when I look for it, the computer tells me that there isn't one installed (There is).
    I tried just restarting it, still doesn't show up. So I shut down, and power-up again. It starts up fast and normal, and then my airport card shows up.
    Any idea what is causing this?
    Thanks in advance!
    Mike

    Hi,
    I just got upgraded to a 2GHz Intel Core Duo (10.4.7)
    by Apple, after they couldn't fix my iMac G5 iSight.
    But ever since I got it, on the initial start up
    every morning, it doesn't start up right away. When I
    press the power button, the sleep light dims on a
    little, stays on for about 30 seconds (with a blank
    screen) then the computer will eventually start up
    (Much much slower than normal)
    Once it finished starting up, and gets to my desktop,
    my airport icon doesn't show up, and when I look for
    it, the computer tells me that there isn't one
    installed (There is).
    I tried just restarting it, still doesn't show up. So
    I shut down, and power-up again. It starts up fast
    and normal, and then my airport card shows up.
    Any idea what is causing this?
    Thanks in advance!
    Mike
    parks2,
    Have you reinstalled your RAM?
    Have you run the Apple Hardware Test? Check System Profiler under Diagnostics after each startup, as well.

  • Starting again to get organised

    Hi chaps ... after several years of screwing up iphoto I want to, maybe, start again and get it good. I have several cameras that download to iphoto and I also have a laptop that I try and synchronise with my desktop mac but it doesn't always happen - think I have a bit of a duplication problem (if I search my hard drive there are, say, several versions of IMG_007.jpg from those different cameras etc. How does iphoto sort these will it not show a duplicate if it's date and time are different (ie if 2 shots with the same file name are shot on different dates are they still dupes) ... anyway I seem to have "lost" a few photographs and wonder if it's down to the duplication problem. Is there an easy way to start all over with a nice clean copy of iphoto ? Many thanks Roger

    Roger
    Yes there is:
    To create and populate a new library:
    Note this will give you a working library with the same film rolls and pictures as before, however, you will lose your albums, keywords, books, calendars etc.
    Move the iPhoto Library Folder to the desktop
    Launch iPhoto. It will ask if you wish to create a new Library. Say Yes.
    Go into the iPhoto Library Folder on your desktop and find the Originals folder. From the Originals folder drag the individual rolls to the iPhoto Window and it will recreate them in the new library.
    When you're sure all is well you can delete the iPhoto Library Folder on your desktop.
    In the future, in addition to your usual back up routine, you might like to make a copy of the library6.iPhoto file whenever you have made changes to the library as protection against database corruption.
    Regards
    TD

  • ITunes starting up and connecting to iStore on its own...?

    As subject describes, iTunes is starting up on its own.
    I was offline just now and got the message 'iTunes cannot connect to iStore..'. I wasn't even using the computer at the time.
    I have no auto updates enabled, or anything else that might require iTunes to start itself and get online automatically. Ping is set to OFF on my iTunes account.
    Can anyone advise what is going on here please??
    cheers,
    Ian

    Just installed Lion and I'm having exactly the same problem! This is a work machine and it is unusable now in presentations!
    I haven't any other threads on this, or any responses to these guys - can someone help please?
    Pete

Maybe you are looking for

  • Import XML data to textfields in a PDF file

    Can I use LiveCycle Designer 8.2 to auto populate textfields in a PDF-file with data from a XML-file when the user opens the PDF-file? If so, how will I do it? Is there any guide? It works fine in the Livecycle Designer preview but when I open the PD

  • You Should Be Ashamed

    To the Adobe Help Team: You should be ashamed. Like many others I recently upgraded my CS6 suite. Much to my surprise when I installed the upgrade I was met with a completely re-written and broken HELP system. Any attempt to access the help through o

  • Bug in applying read only security status to a PDF portfolio?

      Hi, A quick question about setting up a pdf portfolio as 'read only', so users cannot save amended versions of the document within the portfolio, they can only go to 'save as'. I have set this up, using Adobe Professional 9, using the following pro

  • Getting blue question mark for images in Safari

    Hi guys I have MBP 15", early 2011, 250 GB SSD, 16 GB RAM, 10.10 Yosemite OSx and I am facing problem recently is that some images in Safari 8 browser won't open and instead blue question mark will arise . I have friend of mine using ipad2 and I aske

  • Is there a way to combine data from multiple responses (collected from different forms)?

    Since FormCentral (FC) doesn't support XFA-based dynamic forms (utilizing form logic), we have a long form that we may need to separate out into smaller PDF forms.  However, the data from each form needs to remain as a group. Wondering if there's a w