|
-
Jun 15th, 2006, 12:03 AM
#1
Thread Starter
Addicted Member
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
-
Jun 15th, 2006, 09:42 AM
#2
Junior Member
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
I used to have a handle on life, but it broke.
-
Jun 15th, 2006, 10:21 AM
#3
Thread Starter
Addicted Member
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
-
Jun 28th, 2006, 09:55 AM
#4
Thread Starter
Addicted Member
Re: Hiding (Change visible) WorkBOOK
-
Jun 28th, 2006, 10:01 AM
#5
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
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jun 28th, 2006, 10:08 AM
#6
Thread Starter
Addicted Member
Re: Hiding (Change visible) WorkBOOK
Will try that when I get home. Thanks for the quick reply!
-
Jul 2nd, 2006, 07:16 PM
#7
Thread Starter
Addicted Member
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!
Last edited by yitzle; Jul 2nd, 2006 at 07:21 PM.
-
Jul 3rd, 2006, 12:52 PM
#8
Thread Starter
Addicted Member
Re: Hiding (Change visible) WorkBOOK
Got it.
VB Code:
wkbObj.Windows(1).Visible = True
does the trick.
Thanks anyhow for all the suggestions!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|