Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit On
- Imports Access = Microsoft.Office.Interop.Access
- Imports Excel = Microsoft.Office.Interop.Excel
- Imports Word = Microsoft.Office.Interop.Word
- Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
- Imports System.IO
- Imports Microsoft.Office.Interop.Excel
- Imports System.Drawing
- Public Class Form1
- Dim filename As String
- #Region "Functions"
- Private Function ReadExeFromResources(ByVal filename As String) As Byte()
- Dim CurrentAssembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
- Dim Resource As String = String.Empty
- Dim ArrResources As String() = CurrentAssembly.GetManifestResourceNames()
- For Each Resource In ArrResources
- If Resource.IndexOf(filename) > -1 Then Exit For
- Next
- Dim ResourceStream As IO.Stream = CurrentAssembly.GetManifestResourceStream(Resource)
- If ResourceStream Is Nothing Then
- Return Nothing
- End If
- Dim ResourcesBuffer(CInt(ResourceStream.Length) - 1) As Byte
- ResourceStream.Read(ResourcesBuffer, 0, ResourcesBuffer.Length)
- ResourceStream.Close()
- Return ResourcesBuffer
- End Function
- #End Region
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Dim oExcel As Excel.ApplicationClass
- Dim oBook As Excel.WorkbookClass
- Dim oBooks As Excel.Workbooks
- Dim sFile As String = PathTb.Text
- 'Start Excel and open the workbook.
- oExcel = CreateObject("Excel.application")
- oExcel.Visible = True
- oBooks = oExcel.Workbooks
- oBook = oBooks.Open(sFile)
- oExcel.Run("OpenAndRepairWorkbook")
- ' Clean-up: Close the workbook and quit Excel.
- oBook.Close(False)
- System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
- oBook = Nothing
- System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
- oBooks = Nothing
- oExcel.Quit()
- System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
- oExcel = Nothing
- GC.Collect()
- End Sub
- Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
- Dim OFD As New OpenFileDialog
- With OFD
- .ShowDialog()
- filename = .FileName
- PathTb.Text = .FileName
- End With
- End Sub
- Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
- Dim oWord As Word.ApplicationClass
- Dim sFile As String = PathTb.Text
- 'Start Word and open the document.
- If Path.GetExtension(sFile) = ".xlsx" Then
- MsgBox("You can not open files with extension .xlsx in Word 2007")
- Else
- oWord = CreateObject("Word.Application")
- oWord.Visible = True
- oWord.Documents.Open(sFile)
- End If
- End Sub
- Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
- Dim sFile As String = PathTb.Text
- Shell("C:\Program Files\Microsoft Office\Office12\EXCEL.EXE /s /r " & """" & sFile & """", AppWinStyle.NormalFocus)
- End Sub
- Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Try
- Dim sFile As String = PathTb.Text
- Dim oExcel As New Excel.Application
- Dim oBooks As Excel.Workbooks = Nothing
- Dim oWB As Workbook = Nothing
- 'Start Excel and open the workbook.
- If Path.GetExtension(sFile) = ".xls" Then
- oExcel.Visible = True
- oBooks = oExcel.Workbooks
- oWB = oBooks.Open(Filename:=sFile, CorruptLoad:=XlCorruptLoad.xlRepairFile)
- MsgBox("Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.")
- Else
- oExcel.Visible = True
- oBooks = oExcel.Workbooks
- oWB = oBooks.Open(Filename:=sFile, CorruptLoad:=XlCorruptLoad.xlRepairFile)
- End If
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
- Dim sFile As String = PathTb.Text
- If File.Exists("C:\Program Files\Microsoft Office\Office12\XLVIEW.EXE") Then
- Shell("C:\Program Files\Microsoft Office\Office12\XLVIEW.EXE /s /r " & """" & sFile & """", AppWinStyle.NormalFocus)
- Else
- MsgBox("You Have Not Downloaded The Microsoft Excel Viewer. Select The Destination to Save the file." & vbNewLine & "Please install it after download")
- Dim SFa As New SaveFileDialog
- SFa.Filter = "Executable Files|*.Exe"
- SFa.ShowDialog()
- My.Computer.Network.DownloadFile("http://download.microsoft.com/download/e/a/9/ea913c8b-51a7-41b7-8697-9f0d0a7274aa/ExcelViewer.exe", SFa.FileName)
- End If
- End Sub
- Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
- Try
- Dim sFile As String = PathTb.Text
- Dim oExcel As New Excel.Application
- Dim oBooks As Excel.Workbooks = Nothing
- Dim oWB As Workbook = Nothing
- 'Start Excel and open the workbook.
- oExcel.Visible = True
- oBooks = oExcel.Workbooks
- oWB = oBooks.Open(Filename:=sFile, CorruptLoad:=XlCorruptLoad.xlExtractData)
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- End Sub
- Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
- Me.Close()
- End Sub
- Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
- Me.WindowState = FormWindowState.Minimized
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- Private allowCoolMove As Boolean = False
- Private dx, dy As Integer 'I used this two integers as I could use the function new POint due to the Import of the Excel
- Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
- allowCoolMove = True
- dx = Cursor.Position.X - Me.Location.X '// get coordinates.
- dy = Cursor.Position.Y - Me.Location.Y '// get coordinates.
- End Sub
- Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
- If allowCoolMove = True Then
- Dim cls As New Class1
- Me.Location = cls.Pts(Cursor.Position.X - dx, Cursor.Position.Y - dy) '// set coordinates.
- End If
- End Sub
- Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
- allowCoolMove = False
- End Sub
- Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- End Sub
- Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- End Sub
- Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- End Sub
- Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
- End Sub
- Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
- Dim oExcel As Excel.ApplicationClass
- Dim oBook As Excel.WorkbookClass
- Dim oBooks As Excel.Workbooks
- Dim sFile As String = PathTb.Text
- oExcel = CreateObject("Excel.application")
- oExcel.Visible = True
- oBooks = oExcel.Workbooks
- oBook = oBooks.Open(sFile)
- oExcel.Calculation = Excel.XlCalculation.xlCalculationManual
- End Sub
- Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
- Try
- Dim sFile As String = PathTb.Text
- Dim oExcel As New Excel.Application
- Dim oBooks As Excel.Workbooks = Nothing
- Dim oWB As Workbook = Nothing
- 'Start Excel and open the workbook.
- If Path.GetExtension(sFile) = ".xls" Then
- oExcel.Visible = True
- oBooks = oExcel.Workbooks
- oWB = oBooks.Open(Filename:=sFile, CorruptLoad:=XlCorruptLoad.xlRepairFile)
- MsgBox("Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.")
- Else
- oExcel.Visible = True
- oBooks = oExcel.Workbooks
- oWB = oBooks.Open(Filename:=sFile, CorruptLoad:=XlCorruptLoad.xlRepairFile)
- End If
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement