Hiding (Change visible) WorkBOOK
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:
VB Code:
Windows("TimeLogger.xls").Visible = True
Please advise!
My code:
VB 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
Re: Hiding (Change visible) WorkBOOK
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:
Code:
' 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
Re: Hiding (Change visible) WorkBOOK
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
Re: Hiding (Change visible) WorkBOOK
Re: Hiding (Change visible) WorkBOOK
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
VB Code:
Set xlApp = New Excel.Application
to
VB Code:
Set xlApp = New Excel.Application
xlApp.Visible = True
Re: Hiding (Change visible) WorkBOOK
Will try that when I get home. Thanks for the quick reply!
Re: Hiding (Change visible) WorkBOOK
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:
VB Code:
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!
Re: Hiding (Change visible) WorkBOOK
Got it.
VB Code:
wkbObj.Windows(1).Visible = True
does the trick.
Thanks anyhow for all the suggestions!