PDA

Click to See Complete Forum and Search --> : Hiding (Change visible) WorkBOOK


yitzle
Jun 15th, 2006, 12:03 AM
OK.
I can try to open, modify and close a XLS file, and create when it doesn't exist.
However, after modifying the XLS, when I open it, I need to do Window>Unhide>Unhide Workbook.

How do I fix that?
A Excel Macro reveals:
Windows("TimeLogger.xls").Visible = True
Please advise!
My code:
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim wkbBook As Excel.Workbook
Dim wkbObj As Excel.Workbook
Dim xlsfilename As String
xlsfilename = App.Path & "\TimeLogger.xls"

On Error GoTo create
Set wkbObj = GetObject(xlsfilename)
Dim i As Integer
i = 1
While wkbObj.Worksheets(1).Range("A" & i).Value <> ""
i = i + 1
Wend
wkbObj.Worksheets(1).Range("A" & i).Value = Format(Now, "mmmm-dd-yy")
wkbObj.Worksheets(1).Range("B" & i).Value = Format(Now, "h:nn")
wkbObj.Worksheets(1).Range("C" & i).Value = InputBox("Client?")
wkbObj.Worksheets(1).Range("D" & i).Value = InputBox("Description?")
wkbObj.Save

' Till now, all works. Unhide workbook!
Set xlApp = New Excel.Application
Set wkbNewBook = Workbooks.Open(xlsfilename)
wkbNewBook.Visible = True

wkbNewBook.Save
wkbNewBook.Close

Set wkbNewBook = Nothing
Set xlApp = Nothing
' End problem area

Exit Sub

create:
On Error Resume Next
Set xlApp = New Excel.Application
Set wkbNewBook = xlApp.Workbooks.Add()
wkbNewBook.Worksheets(1).Range("A1").Value = "a"
wkbNewBook.Close SaveChanges:=True, FileName:=xlsfilename
xlApp.Quit
Set wkbNewBook = Nothing
Set xlApp = Nothing
End Sub

littlepd
Jun 15th, 2006, 09:42 AM
The list of "allowed values" for setting the visible property are as follows:

- xlSheetHidden
- xlSheetVisible
- xlSheetVeryHidden

Here is an example of unhiding all sheets in a workbook:

' Unhides all worksheets in the workbook, even very hidden worksheets
Public Sub UnhideAllWorksheets()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws

End Sub

yitzle
Jun 15th, 2006, 10:21 AM
Its not working :(
I still think I need to do Workbook.Visible and not Worksheet
It'd truly appreciate if someone could fix my code up...
Project:
www.ecf.utoronto.ca/~goodi/Archive/TimeLog.zip

yitzle
Jun 28th, 2006, 09:55 AM
:bump:

DKenny
Jun 28th, 2006, 10:01 AM
You are creating a new instance of Excel, using the xlApp variable, but you never make that instance of the application visible. If the app isn't visible, then you will never be able to see the workbook.

Change
Set xlApp = New Excel.Application
to
Set xlApp = New Excel.Application
xlApp.Visible = True

yitzle
Jun 28th, 2006, 10:08 AM
Will try that when I get home. Thanks for the quick reply!

yitzle
Jul 2nd, 2006, 07:16 PM
No, that's not it.
I'm not interested in making the app visible. Nor is the problem making the sheet visible.
It is the workbook that is not showing up as visible.

If the file already exits, this is what runs:

Private Sub Command1_Click()
InputBox("Client?") & "," & InputBox("Description?")

Dim wkbObj As Excel.Workbook
Dim xlsfilename As String
xlsfilename = App.Path & "\TimeLogger.xls"

On Error GoTo create
Set wkbObj = GetObject(xlsfilename)
Dim i As Integer
i = 1
While wkbObj.Worksheets(1).Range("A" & i).Value <> ""
i = i + 1
Wend
wkbObj.Worksheets(1).Range("A" & i).Value = Format(Now, "mmmm-dd-yy")
wkbObj.Worksheets(1).Range("B" & i).Value = Format(Now, "h:nn")
wkbObj.Worksheets(1).Range("C" & i).Value = InputBox("Client?")
wkbObj.Worksheets(1).Range("D" & i).Value = InputBox("Description?")
wkbObj.Save
wkbObj.Close

Set wkbObj = Nothing

Exit Sub

The only object used is the Workbook object.
Somehow the Excel workbook becomes hidden after this code.
And the wkbObj does not have a visible, hide, unhide or hidden property.
Please help!

yitzle
Jul 3rd, 2006, 12:52 PM
Got it.
wkbObj.Windows(1).Visible = True
does the trick.
Thanks anyhow for all the suggestions!