I have a simple app, which is something like a launcher for my macro enabled excel workbook. I made it for easier distribution, to be able to check if excel installed and also to make it look and behave like a standalone application.
I am using Office Interop which, according to MS, has many performance issues. But still, have you got any idea what I could improve to perform faster?
Imports System.Threading
Imports Microsoft.Win32
Imports Microsoft.Office.Interop.Excel
Module Module1
Public Sub Main()
On Error GoTo ErrorHandler
Dim singleInstance As Boolean = False
Dim mutex As New Mutex(True, My.Application.Info.AssemblyName,
singleInstance)
Dim excelKey As RegistryKey = Registry.ClassesRoot.OpenSubKey("Excel.Application")
Dim excelInstalled As Boolean = If(excelKey Is Nothing, False, True)
If excelInstalled = True And singleInstance = True Then
SplashForm.Show()
Dim MyAppPath As String = My.Application.Info.DirectoryPath
Dim ExcelFilePath As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "Správce rozpisů 2019\" & "Rozpis1.xlsb")
If Not IO.File.Exists(ExcelFilePath) Then
Dim ExcelfileBackupPath As String = IO.Path.Combine(MyAppPath, "bundle\backup\" & "Rozpis1.xlsb")
If IO.File.Exists(ExcelfileBackupPath) Then
My.Computer.FileSystem.CopyFile(ExcelfileBackupPath, ExcelFilePath, True)
Call Open(ExcelFilePath)
Else
SplashForm.Close()
ErrorForm.ShowDialog()
End
End If
Else
Call Open(ExcelFilePath)
End If
SplashForm.Close()
ElseIf excelInstalled = False Then
SplashForm.Close()
CompatibilityErrorForm.ShowDialog()
ElseIf singleInstance = False Then
MsgBox("Správce rozpisů je již spuštěn.", vbInformation, "Aplikace je již spuštěna")
End If
Exit Sub
ErrorHandler:
MsgBox("Při spouštění Správce rozpisů došlo k chybě.", vbCritical, "Došlo k chybě")
Resume Next
End Sub
Sub Open(openThis As String)
Dim xls As Application = New Application With {
.WindowState = XlWindowState.xlMaximized
}
Dim workbook As Workbook = xls.Workbooks.Open(openThis)
xls.Visible = True
End Sub
End Module