vb.net - Calling Sheet from a WorkBook -


I am trying to call 5th Sheet in an open workbook. Red CurrentRun New Excel.Application Blind CurrentBook Excel.Workbook Slow CurrentSheet Excel.Worksheet Personal Sub General ButtonOpener_Click as as (as: when I seem to be able to do this I open the workbook from this program as the object, as the E EventArgs handles GeneralButtonOpener.Click CurrentRun.Visible = True CurrentBook = CurrentRun.Workbooks.Add (MainTemplatePath) CurrentSheet = CurrentBook.Worksheets (4) CurrentSheet.Activate () End Sub

But calling the sheet is open if the file is already open but all my efforts Q: Current Current Microsoft Office.Interop.Excel.Application as Current Book as Microsoft.Office.Interop .Excel.Workbook Dim CurrentSheet as Microsoft.Office.Interop.Excel .worksheet CurrentRun = System.Runtime.InteropServices.Marshal.GetActiveObject ("Excel.Application") CurrentBook = CurrentRun.Workbooks CurrentSheet = CurrentBook.Sheets (4) CurrentSheet.Activate ()

Or

  Personal sub button 1_Click (as the S-Ender object, in the form of e EventArgs) Handle Button1.Click Due CurrentRun Microsoft.Office.Interop.Excel.Application Default CurrentBook Excel.Workbook Slow CurrentSheet As Excel.Worksheet CurrentRun = System.Runtime.InteropServices.Marshal.GetActiveObject ("Excel. Eidan ") CurrentBook = CurrentRun.ActiveWorkbook CurrentSheet = CurrentBook.Sheets (4) CurrentSheet.Activate () End Sub   

I have seen many examples, but I do not understand where I am getting wrong Which is surprising because there are so many questions about this topic.

Thank you!

It's my surprise, I found out that there are dozens of examples of actually running Excel in the background. When I'm debugging and launching COM, the first example of Excel has started. The second starts when I open the windows form (the main part of the add-in).

What I did not know was that when an exception was thrown, and I stopped things from within the visual studio, only the first instance of Excel was closed. I have a code that tries to clear and clear Excel's applications but it certainly can not be reached because the exception was thrown.

And here I was thinking that I will make an error in handling the error in the short time on the road. I have some more developed things. I obviously need to deal with some basic error which is my build process Are very long ago. I am completely taught, and by no means has it been three years without becoming an issue.

Hopefully someone else was not taught who could see it before pulling his hair for 14 hours.

Solution Close all other instances of Excel and the code above works to deal with the error and clean the addresses previously addressed here: maybe call GC, although this Is controversial.

Last Code:

  .... Import Systems Runtime. Interop Services .... New Exxl as Dim PresentRine Excel as Epilink Dim presentbook Workbook Deem Excel as Current Sheet Worksheets .... Private All Buttons 1_Click (Sender as Object, and Event as ARG) Button 1 Handles. Error Click Go to Goto VortexInYourSoul CurrentRun = System.Runtime.InteropServices.Marshal.GetActiveObject ( "Excel.Application") Wartmanbuk = CurrentRun.Workbooks (1) CurrentRun.Visible = True CurrentSheet = CurrentBook.Sheets (8) CurrentSheet.Activate ( ) CurrentBook.ActiveSheet.name = "Exit from Lama Lala Lammalik" .... Sub VortexInYourSoul: CurrentSheet = Nothing CurrentBook.Close (false) CurrentBook = None CurrentRun.Quit () CurrentRun = None MsgBox ("Error : "And Err.Description) End Sub    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -