Results 1 to 6 of 6

Thread: making a button invisible from vb6 (resolved)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908

    making a button invisible from vb6 (resolved)

    is it possible to make a button in an excel spreadseet to become invisible from vb6 after calling out the excel template?
    Last edited by Goh; Apr 28th, 2004 at 12:54 PM.

  2. #2

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is a small demo I made for you to see how to control the
    command buttons in Excel from VB. The demo creates a new
    workbook and creates a command button in Excel. Then on the
    click of the vb button it will change the visibility of the Excel
    command button.
    VB Code:
    1. 'Add a reference to MS Excel xx.x Object Library
    2. 'Add a reference to MS Office xx.x Object Library
    3. 'Add one command button (Command1)
    4. Option Explicit
    5.  
    6. Dim oXL As Excel.Application
    7. Dim oWB As Excel.Workbook
    8. Dim oSHT As Excel.Worksheet
    9. Dim oSHP As Excel.Shape
    10.  
    11. Private Sub Command1_Click()
    12.     For Each oSHP In oSHT.Shapes
    13.         If oSHP.Type = msoOLEControlObject And oSHP.Name = "CommandButton1" Then
    14.             'Toggle the visibility property of the Excel command button on each click of the vb button
    15.             oSHP.Visible = Not oSHP.Visible
    16.         End If
    17.     Next
    18. End Sub
    19.  
    20. Private Sub Form_Load()
    21.     Set oXL = New Excel.Application
    22.     'Add a new workbook for the demo
    23.     Set oWB = oXL.Workbooks.Add
    24.     oWB.Activate
    25.     oXL.Visible = True
    26.     Set oSHT = oWB.Worksheets("Sheet1")
    27.     'Add a command button to sheet1
    28.     oSHT.Shapes.AddOLEObject Left:=100, Top:=100, Width:=100, Height:=25, ClassType:="Forms.CommandButton.1"
    29. End Sub
    30.  
    31. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    32.     'Clean up
    33.     Set oSHP = Nothing
    34.     Set oSHT = Nothing
    35.     oWB.Close False
    36.     Set oWB = Nothing
    37.     oXL.Quit
    38.     Set oXL = Nothing
    39. End Sub
    Enjoy
    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

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908
    wow! thanks alot man!

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

    Dont forget to resolve your other thread.

    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

  6. #6
    New Member
    Join Date
    Apr 2004
    Posts
    12
    FWIW:

    The button will still be visible in design mode. This is great for the developer since it's hard to change something that you can't see. However, if a user opens the file with macros disabled, the button will be there.

    If this is something that you don't want then it might be better to delete the button instead of just hiding it.

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