MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Can't show a Workbook opened by GetObject()

  Asked By: Heath    Date: Feb 26    Category: MS Office    Views: 2976

I can't make visible a Workbook that I opened using GetObject().
Somebody suggested using the code below:

Dim DB_Workbook As Workbook
On Error Resume Next
Set DB_Workbook = GetObject("C:\Full\Path\To\Workbook.xls")
If Err.Number = 432 Then

MsgBox "Workbook not open."


MsgBox "Workbook open."

End If
DB_Workbook.Application.Visible = True

First, when I run that code, then even when the workbook happens to be
closed, GetObject() always opens it -- so MsgBox "Workbook not open."
is never called -- which is fine by me.

But the main thing is that I get a phenomenon I have already bumped
into. When GetObject() finds that DB_Workbook is not open, and so it
opens it, then, I can access the DB Excel file contents through
another Excel app that I have written (my "Viewer"), but:

- the DB_Workbook remains invisible

- the DB_Workbook does not appear in the Windows task list

So now the next thing I want to be able do, since I am debugging, is
to make the Excel DB_Workbook visible. So I tried coding:

DB_Workbook.Application.Visible = True

But it does not make the DB_Workbook visible. As a matter of fact, I
see from the IDE that DB_Workbook.Application.Visible was already set
to True.




1 Answer Found

Answer #1    Answered By: Woodrow Jones     Answered On: Feb 26

If you are in Excel, you should never use (or need) GetObject -- all
of your Excel objects should be derived from Excel.Application.

Just use Workbooks.Open("C:\Full\Path\To\Workbook.xls") to open and
display whatever workbook  you choose.

Didn't find what you were looking for? Find more on Can't show a Workbook opened by GetObject() Or get search suggestion and latest updates.