MacXL: Workbook Created via Automation Opens as Hidden (193433)



The information in this article applies to:

  • Microsoft Excel 2001 for Mac
  • Microsoft Excel 98 Macintosh Edition

This article was previously published under Q193433

SYMPTOMS

When you open a workbook, the workbook window may be hidden.

CAUSE

This problem occurs if the following conditions are true:
  • The workbook was created by automating the SaveAs method.

    -and-
  • The source workbook was opened by using the GetObject method.

WORKAROUND

To work around the problem, use the appropriate method for your situation.

Method 1: If the Workbook Has Already Been Created

If the workbook has already been created, you must unhide it. To do this, follow these steps:
  1. On the Window menu, click Unhide.
  2. In the Unhide workbook list, click to select your workbook, and then click OK.
  3. On the File menu, click Save.
The workbook will not be hidden the next time you open it.

Method 2: Change the Visual Basic for Applications Code

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around the problem, you can add a line of code to the Visual Basic for Applications code that was used to create the workbook, to unhide the workbook window before it is saved. The following example illustrates the line of code necessary to accomplish this:
Sub AutomationTest()
    Dim xlworkbook As Object
    ' Open the existing file.
    ' Note: Change "HD" to the name of your hard disk.
    Set xlworkbook = GetObject("HD:Test")

    ' Set the Visible property of the workbook window to True.
    ' This will prevent the problem.
    ' Note: This will not make Excel visible during the execution
    ' of this procedure.
    xlworkbook.Parent.Windows(xlworkbook.Name).Visible = True

    With xlworkbook
        ' Save the file as a new name.
        ' Note: Change "HD" to the name of your hard disk.
        .SaveAs "HD:TestA"
        .Close
    End With
    Set xlworkbook = Nothing
End Sub
				

Modification Type:MinorLast Reviewed:10/10/2006
Keywords:kbdtacode kbprb KB193433