Results 1 to 7 of 7

Thread: Excel controls from VB6 program

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    8

    Excel controls from VB6 program

    Hi All;

    I have a little dilemna where i am attempting to alter a control in a worksheet from a Visual Basic 6 program (report generator). I have a chunk of code from a Macro in VB as follows:

    .Application.CommandBars("Visual Basic").Visible = False
    .ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", Link:=False, _
    DisplayAsIcon:=False, Left:=227.25, Top:=66.75, Width:=473.25, Height _
    :=66.75).Select
    .Range("A4:G11").Select
    With Selection.Interior
    .ColorIndex = 36
    .Pattern = xlSolid
    End With


    This creates a textbox on an excel spreadsheet... how do i add text from VB6 to this textbox on an excel spreadsheet? Basically i dont know how to reference the control on the excel from VB...

    any help would be appreciated.. and thanks in advance.

    j

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

    Re: Excel controls from VB6 program

    You can acces any control on any sheet/workbook by accessing its Shapes collection.
    VB Code:
    1. ActiveBook.ActiveSheet.Shapes("Text1")  'etc.
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    8

    Re: Excel controls from VB6 program

    Thanks RobDog... someone from another forum told me that you would know the answer to this...

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    8

    Re: Excel controls from VB6 program

    I have just tried this and i get a "438" error

    Object doesn't support this property or method

    Heres the full code from VB:

    Dim xlsApp As Excel.Application
    Set xlsApp = New Excel.Application
    xlsApp.Workbooks.Add

    ....
    .....
    xlsApp.ActiveBook.ActiveSheet.Shapes("Text1").Text = "HI there"


    Any suggestions ?

  5. #5
    Junior Member
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    30

    Re: Excel controls from VB6 program

    Hmm.

    You can try accessing the textbox directly:
    Sheet1.TextBox1.Text = "HI there"

    But that will not help you if you are creating textboxes dynamically.

    Did you try this:

    VB Code:
    1. Dim textbox1 as Object
    2. Set textbox1 = .ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", Link:=False, _
    3. DisplayAsIcon:=False, Left:=227.25, Top:=66.75, Width:=473.25, Height _
    4. :=66.75)
    5.  
    6. textbox1.Text = "HI there"

    If this works, you can simply keep a reference to the textbox in memory.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    8

    Re: Excel controls from VB6 program

    I get this error again for some reason.. hmmm


    "438" error

    Object doesn't support this property or method

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

    Re: Excel controls from VB6 program

    Try this then.
    VB Code:
    1. ActiveSheet.OLEObjects("TextBox1").Object.Value = "Test"
    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