Check if external program (MS Excel) is active and has opened a particular file

All
I need to find some solution for next problem (Visual Studio 2010). I have a form with some buttons. Those buttons open Excel-files from a network share and the Excel-files are marked as shared (meaning they can be opened/edited by multiple users from different
computers at same time).
Anyway, when the user presses the button on the form, the file opens in Excel as expected. If he presses the button again, the file is opened again in a second Excel instance. I want to build in some check: if the file is already opened in an existing Excel
instance, that instance should become visible.
That's not all: there is a possibility the user already opened the Excel-file before he launched my application. If he then presses the button, the existing Excel-instance (with this particular file) must be shown.
Of course, the user can close his Excel file. So if he then presses the button, a new Excel instance should start up which opens the file.
How can this be done?
Regards
Kris

Hi,
 Here is an example that will find any instances of Excel and check if they have a specified file name opened.  If it is found it will bring the Excel window to the foreground or if it is minimized it will be restored.
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", EntryPoint:="SetForegroundWindow")> _
Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("user32.dll", EntryPoint:="ShowWindow")> _
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("user32.dll", EntryPoint:="IsIconic")> _
Private Shared Function IsIconic(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<UnmanagedFunctionPointer(CallingConvention.StdCall)> _
Private Delegate Function EnumCallBackDelegate(ByVal hwnd As IntPtr, ByVal lParam As IntPtr) As Integer
<DllImport("user32.dll", EntryPoint:="EnumChildWindows")> _
Private Shared Function EnumChildWindows(ByVal hWndParent As IntPtr, ByVal lpEnumFunc As EnumCallBackDelegate, ByVal lParam As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("user32.dll", EntryPoint:="GetWindowTextW")> _
Private Shared Function GetWindowTextW(ByVal hWnd As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpString As System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer
End Function
Private Const SW_RESTORE As Integer = &H9
Private ChildHandles As New List(Of IntPtr)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Check if Excel has "My Excel File.xls" opened
If Not IsExcelFileOpen("My Excel File.xls") Then
MessageBox.Show("Excel does not have this file opened.")
Else
MessageBox.Show("Ecell has this file opened.")
End If
End Sub
Private Function IsExcelFileOpen(ByVal filename As String) As Boolean
ChildHandles.Clear()
For Each p As Process In Process.GetProcessesByName("EXCEL")
EnumChildWindows(p.MainWindowHandle, AddressOf EnumChildWindowProc, 0)
For Each h As IntPtr In ChildHandles
Dim sb As New System.Text.StringBuilder(256)
GetWindowTextW(h, sb, 256)
If sb.ToString.ToLower.Contains(filename.ToLower) Then
If IsIconic(p.MainWindowHandle) Then
ShowWindow(p.MainWindowHandle, SW_RESTORE)
Else
SetForegroundWindow(p.MainWindowHandle)
End If
Return True
End If
Next
Next
Return False
End Function
Private Function EnumChildWindowProc(ByVal hwnd As IntPtr, ByVal lParam As IntPtr) As Integer
ChildHandles.Add(hwnd)
Return 1
End Function
End Class
If you say it can`t be done then i`ll try it

Similar Messages

  • Form Program Name language EN is not active and has no errors

    Dear all,
      I'm new to SAP development.  I have copied the standard RLVSDR40 and made some modification on it.  When i tried to print in lt31.  I encounter the following error:
    "Form <program name> language EN is not active and has no errors".
    Any idea about this?? What is the standard procedure of this kind development??
    Regards,
    Kit

    hi
    first go to SE71 and give Form Name and Original Language of the form and copy it to zform.
    Now open this Zform in change mode and go to Utilities-> change original language to log on language here EN in your case-> and save it.
    Now your Zform is in language EN note tat now when you are opening your zform to modufy you might be trying to change it in DE so change language to EN and then modify it.
    After making changes go to NACE transaction to assign this zform to transaction you are using.
    Nace->choose application->output type->choose your output type->Double click processing routines->you will find one column pdf smartform/scriptname-> here give your zform name
    It will surely work if not get back to me

  • SmartForm language EN is not active and has no errors

    Hi All,
    I am getting an error "Form 'My Form Name' language EN is not active and has no errors ". This a smart form that's currently working fine with an existing company code but when assign this form (form was not changed at all) to another company code and run the dunning statement, it give us the above error. The funny thing is that it is active but still gives us the error.
    Does anyone have any idea why this is and what to do to resolve this.
    Regards.

    Hi,
    Go into ur form in SMARTFORMS t-code............
    In form attributes u have 3 radio buttons right
    select translate into all languages option and activate it...........
    Don't check the 2 check boxes right to dat.....
    Cheers,
    jose.

  • Form zform4 language EN is not active and has no errors

    after executing a program calling script , it gives the following error  after  clicking print preview  : Form zform4 language EN is not active and has no errors .
    pl find solution.

    Moderator message - Welcome to SCN.
    Have you tried activating the form (in SE71)?
    Rob

  • Smartforms: u201C Form  zFORM language EN is not active and has no erroru201D.

    Dear friends
    I am trying to see print preview via tcode LT31 for picking list but getting error  u201C Form   <zFORM >language EN is not active and has no erroru201D.
    Any idea for this?
    Regards
    Pawan

    HI Abhijit,
    Thanks again for your reply, it is true, my form is in active status and showing above message actually I checked the form via menu option then reactivated a few times still I am getting the same error message, this form was working properly till yesterday but when I removed some unwanted text form Table-LINE, and also I removed some comment in code part in initialization. From then I am getting this message while generating print preview ......my guess there will some error in forms which system is not able display via menu option Form -> Check.
    Is there other option to check smartforms? I will recheck the form again where I made last changes.
    Regards
    Pawan

  • TS4268 hi my imessage isnt working so I turned off imessage and now its been saying "waiting for activation" and has been for a long while now? can you please help me!!! Also saying that my apple ID password is inccorrect when its not!

    Hi,
    My imessage isnt working so I turned off imessage and now its been saying "waiting for activation" and has been for a long while now? Also saying that my apple ID password is inccorrect when its not! Can anyone help me?
    Thanks

    While we all have MacBooks in this forum most of us don’t have Lion. There's a Lion Support Community where everybody has Lion.You should also post this question there.  https://discussions.apple.com/community/mac_os/mac_os_x_v10.7_lion

  • My IPhone 5's Imessages just stopped working and I tried restarting and then turning them off and turning them on.  It now says "Waiting for activation" and has said this for 15 minutues.

    My IPhone 5's Imessages just stopped working and I tried restarting and then turning them off and turning them on.  It now says "Waiting for activation" and has said this for 15 minutues.

    At the time of this post, there seems to be a problem with iMessage and Facetime but only some users are affected.
    http://www.apple.com/support/systemstatus/

  • I have bought an Iphone 4 for my daughter from the apple store, I am trying to use a giff gaff sim which has been activated and has credit on it but the phone does not recognise the sim card

    I bought an Iphone 4 for my daughters birthday from the Apple shop, I am trying to use a Giff Gaff sim card which has been activated and has credit on it but the phone keeps giving me the message  "please use a compatable sim"

    Read here:
    http://support.apple.com/kb/HT5014

  • Form Z_FIDUN_A language EN is not active and has no errors

    Hi Everyone,
    I have copied one Smartform from 4.6C to ECC 6.0. and i have activated that Smartform in ECC 6.0. when i tried to print it is giving me the error "Form Z_FIDUN_A language EN is not active and has no errors". I have activated it in EN only.
    Please help me.

    Hi Leela,
    Try running the FM generated for the SmartForm and resolve any errors that might occur.
    Or Else
    the issue must be the customising where the Business Events are trying to call SAP Scripts and not Smartforms.
    Let me know If you require more help on this.
    Edited by: Raj on Oct 29, 2010 1:37 PM

  • Form ZF_J_1IEWT_CERT language EN is not active and has no errors

    Hi,
    i got the following Error while Posting of With Holding Tax Certificates for a vendor through T-Code J1INCERT.
    Form ZF_J_1IEWT_CERT language EN is not active and has no errors
    Please help.....
    Thanks
    Rashmi

    Hi Rashmi,
    In EWT there is a standard form for withholding tax certificate is J_1IEWT_CERT  and your organization has created a new from name ZF_J_1IEWT_CERT . Just ask your ABAPer if this form has been activated and maintained properly.
    Contact your ABAPer will solve the issue.
    Regards,
    Chintan Joshi.

  • Running the external programs from SM69 t-code and RSBDCOS0 report

    Hi All,
      I am trying to execute the external commands from SM69 and RSBDCOS0. It's throwing the below error:
    26.10.2009 17:26:49 Job started                                                                                00           516
    26.10.2009 17:26:50 Step 001 started                                                                                BT           611
    26.10.2009 17:26:50 External command: ZARCHIVELOG_COPY                                                                BT           630
    26.10.2009 17:26:50 Related parameter:                                                                                BT           613
    26.10.2009 17:26:50 Ext. prog.:   > Function: BtcXpgPanicCan't exec external program (No such file or directory)      BT      606
    26.10.2009 17:26:50 Ext. prog.: External program terminated with exit code 1                                          BT           606
    26.10.2009 17:26:50 Ext. prog.: SAPXPG started on <hostname>_<SID>_00, Process ID 1632, Process Number 12   BT           606
    26.10.2009 17:26:50 External program was cancelled                                                                    BT           614
    26.10.2009 17:26:50 Job cancelled                                                                                00           518
    <SID>adm has full authorization on sapxpg.
    Please let me know what might be the wrong.
    Regards,
    Sridhar

    Dear Markus,
       The dev_xpg file contains the below information
    Trace file of external program (trace level 3)
    < Function: BtcTrcInit> Function: BtcXpgStart  External program: mv
      Process id: 29450
      Parent process id: 29449
      Rearrange StdErr to be collected in memory
      Rearrange StdOut to be collected in memory
    In t-code sm21 dont have any thing.
    Regards,
    sridhar

  • I have recently updated my CC programs to the latest version and now all of my files wont open by default into their respective programs, only if I open the program and go to file open and open the file from there. How can I fix this?

    I have recently updated my CC programs to the latest version (CC2014) and now all of my files wont open by default into their respective programs, only if I open the program and go to file>open and open the file from there. How can I fix this?
    I have tried 'Open with' and the version of the program now installed on my computer isn't even suggested as an option and when I browse for it, the file wont open with it anyway

    On Windows (don't know about Mac), the latest version will always take over the file association, and become the default for indd files. It's impossible to change it.
    But there is a plugin for ID that makes this possible. Never tried it myself.
    https://www.rorohiko.com/wordpress/downloads/lightning-brain-soxy/

  • Looking for a program that can handel import and export of palm doc files

    I am looking for a program that can handel the import and export of palm doc Files that can convert them to to either txt or RTF files for Vista 32, running Palm Desktop 7.1.
    Could anyone give me a few suggestions of any plug-ins that would be good me?
    Hearns
    Post relates to: Palm IIIxe
    This question was solved.
    View Solution.

    Ok, you need to clean uninstall Palm desktop 6.2. Install Palm desktop 4.1.4 and download and install documents to go version 6.
    Here are the clean uninstall instructioins for Vista.
    You should first make a copy of your data to have just in case something
    happens. You can find your data files by going to Start --> Documents -->
    Palm OS Desktop. Highlight your Palm Desktop username and right click and
    copy. Then go to your PC desktop right click on a blank spot and select paste.
    If this is the first time you are installing Palm desktop and encountering a problem, skip the previous step.
    Now you want to uninstall Palm Desktop and remove everything that has to do
    with Palm Desktop from your computer.
    Go to the following locations on the PC and delete the folders listed below.
    C:\Program Files\Palm or Palm One
    C:\Users\[Vista Login Name]\appdata\local\virtualstore\Program Files\Palm or
    PalmOne
    C:\Users\[Vista Login Name]\appdata
    *Note you may need to view hidden folders to get to appdata. To do that go
    into your control panel and open folder options. Go to view tab and uncheck
    hide hidden files.
    Once this is done you will need to delete some registry keys from your PC Operating System.
    Word of warning, going here and deleting the wrong thing can cause your PC
    from starting up, crashing and deletion of programs and data. If you feel
    you are unsure of yourself, see if you have a friend that can help you or a
    PC technician that you can pay to help you. This procedure will show them everything they need to delete. To make sure we have a good copy of the current registry, we need to do a backup of the Registry.
    Go to start on the PC, in the search field type "regedit.exe" without quotes.
    Highlight COMPUTER, go to File --> Export. Should pop up with a Save As box.
    Current location is fine, should be in My Documents or save to a location you will remember. In the file name on the bottom type "backup[todaysdate]" i.e. backup07072008. Next, the hard part.
    The easiest way to make sure your working with the correct key, highlight the key i.e. palm quick install, and press delete on your keyboard. It will ask you, are you sure. Say yes. Do the same thing for all keys below.
    If you make a mistake, stop what you are doing. And call a PC technician.
    BUT do not turn off your computer.
    The reg keys are as follows (Note: some of theses reg keys will not be here
    but if they are delete them)
    * HKEY_CURRENT_USER\Software\U.S. Robotics\Palm Quick Install
    * HKEY_CURRENT_USER\Software\U.S. Robotics\PalmOne File Transfer
    * HKEY_CURRENT_USER\Software\U.S. Robotics\Pilot Desktop
    * HKEY_CURRENT_USER\Software\Palm
    * HKEY_CURRENT_USER\Software\Palm, Inc.
    * HKEY_CURRENT_USER\Software\PalmDesktopAutorun
    * HKEY_CURRENT_USER\Software\palmOne
    * HKEY_CURRENT_USER\Software\PalmSource
    * HKEY_LOCAL_MACHINE\Software\PalmSource or anything else that says palm
    Next reboot your computer.
    Then reinstall your palm desktop from the CD and do a hotsync. Use the username that is on the handheld.

  • Get program error message when I try to open a JPG file containing smart objects

    I get a program error(not code #) when I try to open a JPG file in PhotoshopCS3 containing smart objects.
    I am running OS 10.5 on Intel Mac.
    Appreciate any feedback

    Smart Objects are layers.
    JPEG files can't contain layers.
    So, that doesn't quite make sense.
    Also, this is the Windows side of the Photoshop forums :-)

  • FIREFOX 4 CRASHES WHEN I USE THE "BROUSE" MODE TO SELECT A PROGRAM TO OPEN A PARTICULAR FILE TYPE

    USING TOOLS-OPTIONS- APPLICATION BRINGS UP THE PANEL TO SELECT PROGRAMS FOR EACH FILE TYPE. SELECTING "USE OTHER" BRINGS ANOTHER PANEL WITH VARIOUS OPTIONS. NONE OF THESE ARE APPROPRIATE FOR MY SITUATION. AS SOON AS I CLICK "BROWSE" FIREFOX CRASHES. THE SAME THING HAPPENS IF I SELECT AN ATTACHMENT FROM AN EMAIL AND TRY TO CHANGE THE ASSOCIATED PROGRAM BY USING "BROWSE" TO FIND AN APPROPRIATE PROGRAM.

    You can uninstall (remove) the Java Console extensions and disable the Java Quick Starter extension, you do not need them to run Java applets.
    See http://kb.mozillazine.org/Java#Multiple_Java_Console_extensions
    See also http://www.java.com/en/download/help/quickstarter.xml - What is Java Quick Starter (JQS)? What is the benefit of running JQS? - 6.0
    Disable the Java Quick Starter extension: Tools -> Addons -> Extensions<br />
    Control Panel -> Java -> Advanced tab -> Miscellaneous -> Java Quick Starter (disable)
    See:
    * http://kb.mozillazine.org/Firefox_crashes
    * [[Firefox crashes]]
    Create a new profile as a test to check if your current profile is causing the problems.
    See [[Basic Troubleshooting#Make_a_new_profile|Basic Troubleshooting&#58; Make a new profile]]
    There may be extensions and plugins installed by default in a new profile, so check that in "Tools > Add-ons > Extensions & Plugins"
    If that new profile works then you can transfer some files from the old profile to that new profile (be careful not to copy corrupted files)
    See http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

Maybe you are looking for

  • How to print report in Draft and Document

    Dear all, I have a proplem when preview crystal report in Document . I make a form using Crystal report for Incoming payment, then i import to it. For example When i create a document in Incoming Payment and save it. There is no problem with the crys

  • How to use where clause

    Hello, I am using sapnwrfc  for perl to get few information about SAP system.  To get the Applications pruning on SAP system i need to use two tables DF14AVD and DF14T to get Application Name and Description.  table DF14T  contains description of the

  • Loading music onto iphone and ipod touch

    Hi, when i load music onto my ipod touch the artwork and music go on ok. when i load the same music from the same libary onto my iphone the music and artwork doesn't match... can anyone help please ?? thannks

  • I cannot update software on my new mac air

    why is that? plus, when I connect my iphone 5, it says on the mac that I should download a 10.7 itunes or later version....???

  • How do I create camera profiles in Lr 5 for my Nikon D7100 & Fuji X100s?

    I don't know how to create camera profiles in Lr though I've been using it for years. Thanks, Steve