14 Replies - 9984 Views - Last Post: 05 September 2011 - 06:34 PM Rate Topic: -----

#1 Alkis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 04-April 06

Error opening excel file from vb.net 2010

Posted 26 July 2011 - 05:10 AM

Dim excel As New Microsoft.Office.Interop.Excel.Application()
Dim wb As Microsoft.Office.Interop.Excel.Workbook = excel.Workbooks.Open(txtFileLocations.Lines(w))
Dim ws As Microsoft.Office.Interop.Excel.Worksheet = TryCast(excel.ActiveSheet, Microsoft.Office.Interop.Excel.Worksheet)



when the program tries to opens an excel file, it always throws me an error "Office has detected a problem with this file. Editing may hard your computer" and my program crushes.......
The problem appears on the SECOND line, on DIM wb...blahblah..

i went to the office and unclicked the "protected view" checkboxes.. but it still throws me those errors.
my guess is that the office i have in the computer is not the same as the one that my program uses to open excel files (i mean, i loaded/imported some excel.dll files in the program so i guess that will be the one)

But how do i make the program not care if the excel file is "potentially dangerous"? i KNOW it is not.
and i dont understand how did that happen just NOW, out of the blue :S

Is This A Good Question/Topic? 0
  • +

Replies To: Error opening excel file from vb.net 2010

#2 Alkis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 04-April 06

Re: Error opening excel file from vb.net 2010

Posted 26 July 2011 - 01:41 PM

people? anyone? :P
Was This Post Helpful? 0
  • +
  • -

#3 fixo  Icon User is offline

  • D.I.C Regular

Reputation: 85
  • View blog
  • Posts: 335
  • Joined: 10-May 09

Re: Error opening excel file from vb.net 2010

Posted 26 July 2011 - 02:22 PM

Not sure about if this helps,
anyway take a look at:
http://support.micro...b;en-us;Q320369
http://msdn.microsof...office.11).aspx
Was This Post Helpful? 0
  • +
  • -

#4 Alkis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 04-April 06

Re: Error opening excel file from vb.net 2010

Posted 26 July 2011 - 03:40 PM

no, unfortunatelly this isnt the case here
Was This Post Helpful? 0
  • +
  • -

#5 Alkis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 04-April 06

Re: Error opening excel file from vb.net 2010

Posted 29 July 2011 - 03:01 PM

So... can anyone help me a bit with this? :P
Was This Post Helpful? 0
  • +
  • -

#6 fixo  Icon User is offline

  • D.I.C Regular

Reputation: 85
  • View blog
  • Posts: 335
  • Joined: 10-May 09

Re: Error opening excel file from vb.net 2010

Posted 30 July 2011 - 12:56 AM

See here, please:

http://www.sevenforu...1968-post1.html
Was This Post Helpful? 0
  • +
  • -

#7 Alkis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 04-April 06

Re: Error opening excel file from vb.net 2010

Posted 10 August 2011 - 03:25 AM

View Postfixo, on 30 July 2011 - 01:56 AM, said:



unfortunately this doesnt help. if i want to open the file on my computer, i can.

what i can not do, is open the file via my program...
Was This Post Helpful? 0
  • +
  • -

#8 fixo  Icon User is offline

  • D.I.C Regular

Reputation: 85
  • View blog
  • Posts: 335
  • Joined: 10-May 09

Re: Error opening excel file from vb.net 2010

Posted 10 August 2011 - 05:28 AM

Just tried your code 10 times on my end,
it's working good for me
(VB.NET 2010, Win7, Office 2007)
Imports System.IO
'require reference to Microsoft Excel 12.0 Object Library
Module Module1

    Sub Main()
        If Not File.Exists(txtFileLocations.Lines(w)) Then
            MsgBox("Excel file " & txtFileLocations.Lines(w) & " does not exist")
            Return
        End If
        
        Dim excel As New Microsoft.Office.Interop.Excel.Application()
        Try
            excel.Visible = True
            Dim wb As Microsoft.Office.Interop.Excel.Workbook = CType(excel.Workbooks.Open(txtFileLocations.Lines(w)), Microsoft.Office.Interop.Excel.Workbook)
            Dim ws As Microsoft.Office.Interop.Excel.Worksheet = TryCast(excel.ActiveSheet, Microsoft.Office.Interop.Excel.Worksheet)
        Catch ex As System.Exception
            MsgBox(ex.Message & vbLf & ex.StackTrace)
        End Try
    End Sub

End Module

Was This Post Helpful? 0
  • +
  • -

#9 Alkis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 04-April 06

Re: Error opening excel file from vb.net 2010

Posted 10 August 2011 - 08:39 AM

It works great when the excel document does not open in protected view

But if it does, then the program cannot open it
Was This Post Helpful? 0
  • +
  • -

#10 liviuz  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 18-August 11

Re: Error opening excel file from vb.net 2010

Posted 18 August 2011 - 09:26 AM

Did you have a resolution to this error as I am getting a similar error myself.

View PostAlkis, on 10 August 2011 - 08:39 AM, said:

It works great when the excel document does not open in protected view

But if it does, then the program cannot open it

Was This Post Helpful? 0
  • +
  • -

#11 Alkis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 04-April 06

Re: Error opening excel file from vb.net 2010

Posted 20 August 2011 - 01:29 PM

unfortunately i have yet to find a solution :(
Was This Post Helpful? 0
  • +
  • -

#12 Alkis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 04-April 06

Re: Error opening excel file from vb.net 2010

Posted 03 September 2011 - 12:53 AM

Anyone? anyone at all???
i really need to be able to open all excel files, protected-view and non-protected view alike

btw, the file that i try to open and makes my life miserable is this:
http://www.opap.gr/documents/10157/30233/kino_2011_04.xls

Was This Post Helpful? 0
  • +
  • -

#13 fixo  Icon User is offline

  • D.I.C Regular

Reputation: 85
  • View blog
  • Posts: 335
  • Joined: 10-May 09

Re: Error opening excel file from vb.net 2010

Posted 03 September 2011 - 08:51 AM

You have to turn off protected view manually
before of the opening file, I think

Take a look at :
http://www.webtlk.co...in-office-2010/
Was This Post Helpful? 0
  • +
  • -

#14 liviuz  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 18-August 11

Re: Error opening excel file from vb.net 2010

Posted 05 September 2011 - 01:28 AM

View PostAlkis, on 03 September 2011 - 12:53 AM, said:

Anyone? anyone at all???
i really need to be able to open all excel files, protected-view and non-protected view alike

btw, the file that i try to open and makes my life miserable is this:
http://www.opap.gr/documents/10157/30233/kino_2011_04.xls


I managed to solve this problem by using the ProtectedViewWindows object, new in Office 2010. Here is my code, although in C#:

Excel.Application xcl = new Excel.ApplicationClass();
Excel.ProtectedViewWindow pvw = xcl.ProtectedViewWindows.Open(filename);
Excel.Workbook wkBook = pvw.Workbook;
..........


I hope this helps.
Was This Post Helpful? 1
  • +
  • -

#15 Pit Ufo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-October 08

Re: Error opening excel file from vb.net 2010

Posted 05 September 2011 - 06:34 PM

Why donīt you just open the file with the Proccess Class?

Process.start("My File Path") 

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1