Results 1 to 4 of 4

Thread: Excel in VB

  1. #1

    Thread Starter
    Hyperactive Member fasi's Avatar
    Join Date
    Nov 2000
    Posts
    474

    Angry Excel in VB

    I have a vb 6 program that is writing to an excel sheet on the network. The users have access to this file as well. Some time when the users leave at night they leave the file open and the program cannot write to it. and hangs in the scheduler. Is there a way of checking if the file is already open and who has it open .

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Excel in VB

    you could shut down the pc, which closes everything off.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel in VB

    Here is some code to enumerate the Excel users on a workbook. Should do the trick.
    VB Code:
    1. Private Sub Workbook_Open()
    2.  
    3.     users = ActiveWorkbook.UserStatus
    4.     With Workbooks.Add.Sheets(1)
    5.         For Row = 1 To UBound(users, 1)
    6.             .Cells(Row, 1) = users(Row, 1)
    7.             .Cells(Row, 2) = users(Row, 2)
    8.             Select Case users(Row, 3)
    9.                 Case 1
    10.                     .Cells(Row, 3).Value = "Exclusive"
    11.                 Case 2
    12.                     .Cells(Row, 3).Value = "Shared"
    13.             End Select
    14.         Next
    15.     End With
    16.  
    17. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel in VB

    Quote Originally Posted by dglienna
    you could shut down the pc, which closes everything off.
    Now why would you want to take the chance of corrupting the workbook with an unexpected shutdown/disconnection.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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