Good morning,

Can anyone help me to with this code? I developed a code as a test to check if a excel file is open. The file is "Livro2.xlsx" as the code seems to work but when the file is closed and the code opens the file it suddendly closes it, and I want that the file stays opened.

Sub Livro2()
Dim objExcel As Object

On Error Resume Next
Set objExcel = GetObject("Livro2.xlsx")

If Err.Number <> 0 Then
MsgBox "File Open"

Else

MsgBox "file closed"
Set objExcel = CreateObject("Excel.Application")
Set objExcel = objExcel.Workbooks.Open("C:\Users\njesus\Documentos\Livro2.xlsx")
objExcel.Application.Visible = True

End If
End Sub
Best regards