Question opening excel file

gr8Jain

New member
Joined
Apr 16, 2009
Messages
1
Location
Mumbai, India
Programming Experience
5-10
hi all
i need help
i am using vb.net application programm for opening a excel file.
the code is below-
——————————
Imports Microsoft.Office.Interop.Excel
Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1
Public xlApp As New Excel.Application

Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click
Dim strFileName As String
strFileName = “C:\Documents and Settings\admin\My Documents\Book1.xls”
TextBox1.Text = strFileName
Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture()
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo(”en-US”)

Dim xlWB As Workbook
xlWB = xlApp.Workbooks.Open(strFileName)

xlWB.Application.Visible = True
End Sub
End Class
————————-

This works fine and without any error opening MS excel file.
I am using these reference-
——————–
microsoft excel 12.0 object library=Microsoft.Office.Interop.Excel.dll
microsoft office 12.0 object library=office.dll
microsoft visual basic for application extensiblity 5.3=Interop.VBIDE.dll
———————

My problem is that i am using same reference and same code for web application but it not working there.
everything is there is ok only last line of code is not set to true when debug and not open excel file and no error displayed.
—————
xlWB.Application.Visible = True
‘this shown to me as false in debug
———-
Please help me in this . … . . .
 

ggunter

Well-known member
Joined
Apr 23, 2008
Messages
137
Programming Experience
Beginner
I use the Interop's; like so:

VB.NET:
Public Function OpenExcelWorkbook(Optional ByVal xlsPath As String = Nothing, _
   Optional ByVal isVisible As Boolean = True)As xlsReturns

   Try
      'initialize
      xlsApp = New Microsoft.Office.Interop.Excel.Application

      'check for path
      If xlsPath <> Nothing Then
         'open indicated workbook
         xlsWrkbk = xlsApp.Workbooks.Open(xlsPath)
      Else
         'open blank workbook
         xlsWrkbk = xlsApp.Workbooks.Add()
      End If

      'turn off alerts
      xlsApp.DisplayAlerts = False

      'check for hidden workbook
      xlsApp.Visible = isVisible

      'set return value
      OpenExcelWorkbook = xlsReturns.Ok
   Catch ex As Exception
      MessageBox.Show(ex.Message)
   
      'set return value
      OpenExcelWorkbook = xlsReturns.OpenError
   End Try

End Function


The return values are enum's I set up myself.
 
Top Bottom