Hi Team,
I was wondering if I am the only one who is not able to do it or what.
Well, as the title suggests, I would like to OPen Excel in vb.net. I was able to find end number of articles online on this but none would help.
It all comes to this, as soon as I run my program, it gives me an option to Open, Save or Cancel but wouldn't open within VS.
here's my code. Please guide:
Imports Excel = Microsoft.Office.Interop.Excel
Imports Office = Microsoft.Office.Core
Public Class Training_Forms
Private xlApp As New Excel.Application
Private xlWook As Excel.Workbook
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
With xlApp.CommandBars("Standard")
.Position = Microsoft.Office.Core.MsoBarPosition.msoBarTop
.Visible = True
End With
With xlApp.CommandBars("Worksheet Menu Bar")
.Position = Microsoft.Office.Core.MsoBarPosition.msoBarTop
.Visible = True
End With
End Sub
Private Sub OpenToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click
Dim OpenBatch As String = InputBox("Please Enter The Batch Number in Numerical Value Only", "Open a Batch Folder", "00")
Try
If OpenBatch = "00" Then
MsgBox("Please enter a valid batch number")
ElseIf OpenBatch = "" Then
MsgBox("Process Cancelled")
Else
Me.WebBrowser1.Navigate("\\10.197.50.253\Department\Training\Batch " + OpenBatch + "\BatchForm.xlsx") 'xlWook.FullName)
End If
Catch ex As Exception
End Try
End Sub
Private Sub NewToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click
Dim NewBatch As String = InputBox("Please Enter The Batch Number in Numerical Value Only", "Create New Batch Folder", "00")
Try
If NewBatch = "00" Then
MsgBox("Please enter a valid batch number")
ElseIf NewBatch = "" Then
MsgBox("Process Cancelled")
Else
If (Not System.IO.Directory.Exists("\\10.197.50.253\Department\Training\Batch " + NewBatch + "")) Then
System.IO.Directory.CreateDirectory("\\10.197.50.253\Department\Training\Batch " + NewBatch + "")
FileToCopy = "\\10.197.50.253\Department\Training\BatchForm.xlsx"
NewCopy = "\\10.197.50.253\Department\Training\Batch " + NewBatch + "\BatchForm.xlsx"
MsgBox("Success!", MsgBoxStyle.Information)
System.IO.File.Copy(FileToCopy, NewCopy)
End If
End If
Catch ex As Exception
End Try
End Sub
End Class