Public Sub Close_Microsoft_Office_Activation_Wizard_And_Open_Excel_File(strExcelPath As String, strExcelFile As String, Optional strPassword As String)
'The purpose of this function is to close the Microsoft Office Activation Wizard dialog box if it exists and open strExcelFile.
Const SW_SHOWNORMAL = 1
Const SW_MAXIMIZE = 3
Const WM_SYSKEYDOWN = &H104
Const WM_SETTEXT As Long = &HC
Const WM_KEYDOWN As Integer = &H100
Const WM_KEYUP As Integer = &H101
Const GW_CHILD = 5
Const WM_SHIFT = &H10 'SHIFT
Const WM_C = &H43 'Capital C
Const WM_H = &H48 'Capital H
Const WM_K = &H4B 'Capital K
Const WM_R = &H52 'Capital R
Dim strFile As String
Dim strLine1 As String
Dim strLine2 As String
Dim strLine3 As String
Dim strVBSFile As String
Dim wsh As Object
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim fso As Object
Dim objTextFile As Object
Dim WinWnd As Long
Set fso = CreateObject("Scripting.FileSystemObject")
strFilePath = CurrentProject.Path & "\"
strVBSFile = "Open MS Excel File.vbs"
strFile = Chr(34) & strFilePath & strVBSFile & Chr(34)
Call DeleteSpecificFile(strFilePath & strVBSFile)
strLine1 = "Set objExcel = CreateObject(" & Chr(34) & "Excel.Application" & Chr(34) & ")"
strLine2 = "objExcel.Visible = True"
strLine3 = "objExcel.Workbooks.Open" & Chr(34) & strExcelPath & strExcelFile & Chr(34)
If strPassword <> "" Then
strLine3 = "objExcel.Workbooks.Open" & Chr(34) & strExcelPath & strExcelFile & Chr(34) & Chr(44) & Chr(44) & Chr(44) & Chr(44) & Chr(34) & strPassword & Chr(34)
End If
Set objTextFile = fso.CreateTextFile(strFilePath & strVBSFile)
With objTextFile
.WriteLine strLine1
.WriteLine strLine2
.WriteLine strLine3
.Close
End With
Set fso = Nothing
Set objTextFile = Nothing
Set wsh = VBA.CreateObject("WScript.Shell")
wsh.Run strFile, windowStyle, waitOnReturn
Set wsh = Nothing
Sleep (2500)
WinWnd = FindWindow(vbNullString, "Microsoft Office Activation Wizard")
If WinWnd <> 0 Then
Call SendMessage(WinWnd, WM_SHIFT, WM_C, 0)
End If
Call DeleteSpecificFile(strFilePath & strVBSFile)
End Sub