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")
- 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("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("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
- Private Sub Label2_Click(sender As System.Object, e As System.EventArgs) Handles Label2.Click
- End Sub
- Private Sub PictureBox9_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox9.Click
- Dim oExcel As Excel.ApplicationClass
- Dim oBook As Excel.WorkbookClass
- Dim sFile As String = PathTb.Text
- oExcel = CreateObject("Excel.application")
- oBook = oExcel.Workbooks.Add
- oExcel.Visible = True
- oBook.Activate()
- oExcel.Calculation = Excel.XlCalculation.xlCalculationAutomatic
- oExcel.Range("A1").Value = "=" & "'" & sFile & "'" & "!A1"
- Dim rRange As Range
- On Error Resume Next
- oExcel.DisplayAlerts = False
- rRange = oExcel.InputBox(Prompt:= _
- "Please select a range similar in size to your corrupt data that you wish to recover.", _
- Title:="SPECIFY RANGE", Type:=8)
- On Error GoTo 0
- oExcel.DisplayAlerts = True
- If rRange Is Nothing Then
- Exit Sub
- Else
- oExcel.Range("A1").Copy()
- oBook.ActiveSheet.Paste(rRange)
- End If
- End Sub
- Private Sub PictureBox10_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox10.Click
- Dim oExcel As New Excel.Application
- Dim oBooks As Excel.Workbooks = Nothing
- Dim oBook As Workbook = Nothing
- Dim oWSheet As Worksheet = Nothing
- Dim sFile As String = PathTb.Text
- Dim sFileName As String = Path.GetFileNameWithoutExtension(sFile)
- Dim sDirName As String = Path.GetDirectoryName(sFile)
- Dim sFileSylkName As String = sDirName & "\" & sFileName & ".slk"
- 'Start Excel and open the workbook.
- oExcel.Visible = False
- oBooks = oExcel.Workbooks
- oBook = oBooks.Open(Filename:=sFile)
- oWSheet = oBook.ActiveSheet()
- oWSheet.SaveAs(Filename:=sFileSylkName, FileFormat:=Excel.XlFileFormat.xlSYLK)
- If File.Exists(sFileSylkName) Then
- oBook.Close()
- oExcel.Visible = True
- oBook = oBooks.Open(Filename:=sFileSylkName)
- Else
- MessageBox.Show("Failed to create " & sFileSylkName)
- End If
- End Sub
- Private Sub Label5_Click(sender As System.Object, e As System.EventArgs) Handles Label5.Click
- End Sub
- Private Sub PictureBox11_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox11.Click
- Dim sFile As String = PathTb.Text
- Shell("C:\Program Files\Windows NT\Accessories\wordpad.exe" + " """ + sFile + """", AppWinStyle.NormalFocus)
- Dim regVersion As Microsoft.Win32.RegistryKey
- regVersion = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\wordpad.exe", True)
- If regVersion IsNot Nothing Then
- Dim proc As New Process
- With proc.StartInfo
- .FileName = regVersion.GetValue("").ToString
- .Arguments = sFile
- End With
- proc.Start()
- End If
- End Sub
- Private Sub PictureBox12_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox12.Click
- Dim oExcel As New Excel.Application
- Dim oBooks As Excel.Workbooks = Nothing
- Dim oBook As Workbook = Nothing
- Dim oWSheet As Worksheet = Nothing
- Dim oChart As Chart = Nothing
- Dim sFile As String = PathTb.Text
- Dim NumberOfRows As Integer
- Dim X As Object
- Dim Counter As Integer = 2
- oExcel.Visible = True
- oBooks = oExcel.Workbooks
- oBook = oBooks.Open(Filename:=sFile)
- oWSheet = oBook.Worksheets.Add()
- oWSheet.Name = "ChartData"
- oWSheet.Activate()
- MsgBox("Select the chart you wish to extract data from.")
- oChart = oBook.ActiveChart
- ' Calculate the number of rows of data.
- NumberOfRows = UBound(oChart.SeriesCollection(1).Values)
- oWSheet.Cells(1, 1) = "X Values"
- ' Write x-axis values to worksheet.
- With oWSheet
- .Range(.Cells(2, 1), _
- .Cells(NumberOfRows + 1, 1)).Value = _
- oExcel.WorksheetFunction.Transpose(oChart.SeriesCollection(1).XValues)
- End With
- ' Loop through all series in the chart and write their values to
- ' the worksheet.
- For Each X In oChart.SeriesCollection
- oWSheet.Cells(1, Counter) = X.Name
- With oWSheet
- .Range(.Cells(2, Counter), _
- .Cells(NumberOfRows + 1, Counter)).Value = _
- oExcel.WorksheetFunction.Transpose(X.Values)
- End With
- Counter = Counter + 1
- Next
- End Sub
- Private Sub releaseObject(ByVal obj As Object)
- Try
- System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
- obj = Nothing
- Catch ex As Exception
- obj = Nothing
- Finally
- GC.Collect()
- End Try
- End Sub
- Private Sub Label11_Click(sender As System.Object, e As System.EventArgs) Handles Label11.Click
- End Sub
- Private Sub Button1_Click_2(sender As System.Object, e As System.EventArgs) Handles Button1.Click
- Alphaleonis.Win32.Vss.VssImplementation.Equals()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement