azizrasul
Well-known Member
- Joined
- Jul 7, 2003
- Messages
- 1,304
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
I have the following code. In the Else part of the code, after the wb.Activate line, what code can I place here that will assign wb.Name to the
objExcelApp object ao that when the line .Visible = False kicks in, it will make the already opened MS Excel file invisible.
objExcelApp object ao that when the line .Visible = False kicks in, it will make the already opened MS Excel file invisible.
Code:
Dim strExcelFile As String
Dim wb As Workbook
Set objExcelApp = GetObject(, "Excel.Application")
If objExcelApp Is Nothing Then
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Workbooks.Open FileName:=strExcelFile
Else
For Each wb In objExcelApp.Workbooks
If wb.Name = Right(strExcelFile, Len(strExcelFile) - InStrRev(strExcelFile, "\")) Then
wb.Activate
Exit For
End If
Next wb
End If
With objExcelApp
.Visible = False
'other code
End With