Making an Excel file invisible

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. 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.

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
 
I understand what you are saying. Thanks for the comprehensive reply.
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
No problem you are welcome.

A final note, be sure to read this article to understand a common pitfall about using Excel objects in Access (not properly "chaining" or "tying" objects can lead to "auto-instantiation" and extra Excel objects floating around your computer -- hence, always being careful to use reference variables for your objects is the right practice):

Why Excel has a problem when using code in access | BTAB Development
 
Upvote 0
Explains why I have had this problem in the past with new EXCEL lines in the TM. I always got it to work if I 'tied' the action back to the Excel object as your link is saying.
 
Upvote 0

Forum statistics

Threads
1,215,764
Messages
6,126,750
Members
449,335
Latest member
Tanne

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top