Results 1 to 8 of 8

Thread: Hiding (Change visible) WorkBOOK

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Toronto, ON Canada
    Posts
    153

    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:
    1. Windows("TimeLogger.xls").Visible = True
    Please advise!
    My code:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim xlApp As Excel.Application
    3.     Dim wkbBook As Excel.Workbook
    4.     Dim wkbObj As Excel.Workbook
    5.     Dim xlsfilename As String
    6.     xlsfilename = App.Path & "\TimeLogger.xls"
    7.    
    8. On Error GoTo create
    9.     Set wkbObj = GetObject(xlsfilename)
    10.     Dim i As Integer
    11.     i = 1
    12.     While wkbObj.Worksheets(1).Range("A" & i).Value <> ""
    13.         i = i + 1
    14.     Wend
    15.     wkbObj.Worksheets(1).Range("A" & i).Value = Format(Now, "mmmm-dd-yy")
    16.     wkbObj.Worksheets(1).Range("B" & i).Value = Format(Now, "h:nn")
    17.     wkbObj.Worksheets(1).Range("C" & i).Value = InputBox("Client?")
    18.     wkbObj.Worksheets(1).Range("D" & i).Value = InputBox("Description?")
    19.     wkbObj.Save
    20.    
    21.     ' Till now, all works. Unhide workbook!
    22.     Set xlApp = New Excel.Application
    23.     Set wkbNewBook = Workbooks.Open(xlsfilename)
    24.     wkbNewBook.Visible = True
    25.    
    26.     wkbNewBook.Save
    27.     wkbNewBook.Close
    28.    
    29.     Set wkbNewBook = Nothing
    30.     Set xlApp = Nothing
    31.     ' End problem area
    32.    
    33.     Exit Sub
    34.        
    35. create:
    36. On Error Resume Next
    37.     Set xlApp = New Excel.Application
    38.     Set wkbNewBook = xlApp.Workbooks.Add()
    39.     wkbNewBook.Worksheets(1).Range("A1").Value = "a"
    40.     wkbNewBook.Close SaveChanges:=True, FileName:=xlsfilename
    41.     xlApp.Quit
    42.     Set wkbNewBook = Nothing
    43.     Set xlApp = Nothing
    44. End Sub

  2. #2
    Junior Member littlepd's Avatar
    Join Date
    Jun 2006
    Location
    Lewisville, TX
    Posts
    28

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Toronto, ON Canada
    Posts
    153

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Toronto, ON Canada
    Posts
    153

    Re: Hiding (Change visible) WorkBOOK

    :bump:

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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:
    1. Set xlApp = New Excel.Application
    to
    VB Code:
    1. Set xlApp = New Excel.Application
    2. xlApp.Visible = True
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Toronto, ON Canada
    Posts
    153

    Re: Hiding (Change visible) WorkBOOK

    Will try that when I get home. Thanks for the quick reply!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Toronto, ON Canada
    Posts
    153

    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:
    1. Private Sub Command1_Click()
    2.     InputBox("Client?") & "," & InputBox("Description?")
    3.  
    4.     Dim wkbObj As Excel.Workbook
    5.     Dim xlsfilename As String
    6.     xlsfilename = App.Path & "\TimeLogger.xls"
    7.    
    8. On Error GoTo create
    9.     Set wkbObj = GetObject(xlsfilename)
    10.     Dim i As Integer
    11.     i = 1
    12.     While wkbObj.Worksheets(1).Range("A" & i).Value <> ""
    13.         i = i + 1
    14.     Wend
    15.     wkbObj.Worksheets(1).Range("A" & i).Value = Format(Now, "mmmm-dd-yy")
    16.     wkbObj.Worksheets(1).Range("B" & i).Value = Format(Now, "h:nn")
    17.     wkbObj.Worksheets(1).Range("C" & i).Value = InputBox("Client?")
    18.     wkbObj.Worksheets(1).Range("D" & i).Value = InputBox("Description?")
    19.     wkbObj.Save
    20.     wkbObj.Close
    21.    
    22.     Set wkbObj = Nothing
    23.    
    24.     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.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Toronto, ON Canada
    Posts
    153

    Re: Hiding (Change visible) WorkBOOK

    Got it.
    VB Code:
    1. 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
  •  



Click Here to Expand Forum to Full Width