|
-
Feb 1st, 2005, 10:56 PM
#1
Thread Starter
New Member
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
-
Feb 1st, 2005, 11:39 PM
#2
Re: Excel controls from VB6 program
You can acces any control on any sheet/workbook by accessing its Shapes collection.
VB Code:
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 2nd, 2005, 07:59 AM
#3
Thread Starter
New Member
Re: Excel controls from VB6 program
Thanks RobDog... someone from another forum told me that you would know the answer to this...
-
Feb 2nd, 2005, 09:58 AM
#4
Thread Starter
New Member
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 ?
-
Feb 2nd, 2005, 10:21 AM
#5
Junior Member
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:
Dim textbox1 as Object
Set textbox1 = .ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=227.25, Top:=66.75, Width:=473.25, Height _
:=66.75)
textbox1.Text = "HI there"
If this works, you can simply keep a reference to the textbox in memory.
-
Feb 2nd, 2005, 10:25 AM
#6
Thread Starter
New Member
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
-
Feb 2nd, 2005, 08:13 PM
#7
Re: Excel controls from VB6 program
Try this then.
VB Code:
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|