vb.net Excel throws COMException (0x800A03EC) at XlSheetVisibility.xlSheetHidden -


i have issue excel-addin i'm making: import csv file, stuff hide sheet (xl_temp_worksheet) xl_temp_worksheet.visible = xlsheetvisibility.xlsheethidden. now, far good. if close workbook , start over, excel throws around exception: system.runtime.interopservices.comexception (0x800a03ec): exception hresult: 0x800a03ec @ microsoft.office.interop.excel._worksheet.set_visible(xlsheetvisibility rhs). i've tried many things, don't know begin list i've done far....

  • marshal.comrelease xl_temp_worksheet
  • set nothing before , after

if put part hide sheet try catch sheet wont hide.

this import function:

    private function import(title string, optional hideimportedsheet boolean = true, optional randomtabname boolean = false) boolean          import = false          dim xl_temp_worksheet worksheet = nothing          try             dim fod new openfiledialog             fod                 .initialdirectory = io.path.combine(ctype(environment.specialfolder.userprofile, string), "downloads")                 .multiselect = false                 .title = title                 .filter = "csv data files (*.csv)|*csv|text files (*.txt)|*.txt|all files (*.*)|*.*"             end              if fod.showdialog() = dialogresult.ok                 xlmyworkbook = xlmyapp.activeworkbook                  dim strsheetname string = "error log " & io.path.getfilenamewithoutextension(fod.filename).replace("data_", "")                 end if                  ' make sure, there opend (or new) document present                 if not xlmyworkbook nothing                      ' if data imported, abort                     each xlws worksheet in xlmyworkbook.worksheets                         if xlws.name.tolower = truncatename(strsheetname.tolower)                             messagebox.show("diese daten (" & fod.filename & ") wurden bereits importiert. der import-vorgang wird abgebrochen.", "daten bereits vorhanden", buttons:=messageboxbuttons.ok, icon:=messageboxicon.stop)                             return false                         end if                     next                      xlmyworkbook.worksheets.add()                 else                      xlmyworkbook = xlmyapp.workbooks.add() ' xlmyapp.activeworkbook                 end if                  xl_temp_worksheet = directcast(xlmyworkbook.activesheet, worksheet)                 ' rename sheet                 xl_temp_worksheet.name = truncatename(strsheetname)                  xl_temp_worksheet.querytables.add(connection:="text;" & fod.filename, destination:=xl_temp_worksheet.range("$a$1"))                     .name = "data_" & strsheetname                     .fieldnames = true                     .rownumbers = false                     .filladjacentformulas = false                     .preserveformatting = true                     .refreshonfileopen = false                     .refreshstyle = xlcellinsertionmode.xloverwritecells                     .savepassword = false                     .savedata = true                     .adjustcolumnwidth = true                     .refreshperiod = 0                     .textfilepromptonrefresh = false                     .textfileplatform = 65001 ' utf8                     .textfilestartrow = 1                     .textfileparsetype = xltextparsingtype.xldelimited                     .textfiletextqualifier = xltextqualifier.xltextqualifierdoublequote                     .textfilesemicolondelimiter = true                     .textfiletrailingminusnumbers = true                     .refresh(backgroundquery:=false)                 end                  try                     '' wont work after closing workbook , starting over!                     if hideimportedsheet = true , xl_temp_worksheet.visible = xlsheetvisibility.xlsheetvisible                         xl_temp_worksheet.activate()                         xl_temp_worksheet.visible = xlsheetvisibility.xlsheethidden                     end if                 catch exception                     debug.print(" # # # # # # # # # #  e  r  r  o  r  # # # # # # ")                     debug.indent()                     debug.print(it.tostring)                     debug.print(" # # # # # # # # # #  e  r  r  o  r  # # # # # # ")                 end try                  import = true              end if         catch ex exception             msg(ex)                      xlmyworksheet = xl_temp_worksheet          end try      end function 

any hint appreciated! if need more info, please let me know. (i think when application_workbookdeactivate something's not released ... that's set nothing ... well, without suggess.)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -