Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Why can my Form only open once per Excel session?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pinkfloydfan - 28 Jan 2008 17:43 GMT
Hi there

I'm still creating a Form to be used in Excel.  The Form is opened via
a vba macro which calls a C# wrapper within an xll that opens the
Form, like this:

VBA:

   Sub TestMacro2()
       Call Application.Run("OpenForm")
   End Sub

C#:

public class XLFormWrap
{
   [STAThread]
   public static void OpenForm()
   {
       XLForm Form1 = new XLForm();
       Form1.ShowDialog();
   }
}

What is strange is that while the first time I run the vba macro the
form opens up, any subsequent time produces nothing.  I have to close
the session of Excel and reopen it to get the form to open again.

Does anyone know why this would happen please?

Many Thanks
Lloyd
Nicholas Paldino [.NET/C# MVP] - 28 Jan 2008 18:00 GMT
Can you wrap in some error catching/detecting code (either in the macro
or in the call to OpenForm) to see if there is an error that is occuring?

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi there
>
[quoted text clipped - 28 lines]
> Many Thanks
> Lloyd
pinkfloydfan - 28 Jan 2008 18:32 GMT
Nicholas

I am very new to C#:  I don't yet know how to write error catching
code...what sort of error would you be expecting?

One other interesting thing: if I just test the "OpenForm" macro
within Visual C# it can be run as many times as I like.

All rather confusing...
Nicholas Paldino [.NET/C# MVP] - 28 Jan 2008 19:02 GMT
Well, you could wrap the call to open the form in a try/catch block, and
see what exception is thrown (if any).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Nicholas
>
[quoted text clipped - 5 lines]
>
> All rather confusing...
pinkfloydfan - 28 Jan 2008 20:02 GMT
Brilliant!

The problem was that I had the following line:

System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false)

and you can't use this if you are calling the macro from another
application.  Ah well, that will teach me to just lift code I don't
fully understand.

Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.