473,239 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,239 software developers and data experts.

Using vb.net to dynamically create excel activeX controls

Using VB.net, i want to dynamically create a workbook and add a command botton to one of the sheets. how would i do this. I see example using VBA but i am not able to translate them to Vb.net. Also, after having created the button, how would I be able to defines an event for it (such as the click event). Thanks
Mar 9 '07 #1
2 5597
807 Expert 512MB
This should get you started. HTH --Sam
Note -- Before you start, add an Excel Reference to your solution: Solution Explorer - right-click on References - Add - COM Tab - MS Excel Obj Lib. Also, before you start, open Excel, Tools-Macros-Security-Trust Tab-Trust Access to Visual Basic Project.
Expand|Select|Wrap|Line Numbers
  1.         Dim xlApp As Excel.Application
  2.         Dim xlBook As Excel.Workbook
  3.         Dim xlSheet As Excel.Worksheet
  4.         Dim xlButton As Excel.OLEObject
  5.         Dim iStartLine As Long
  6.         xlApp = New Excel.Application
  7.         xlApp.Visible = True
  8.         xlBook = xlApp.Workbooks.Add
  9.         xlSheet = xlBook.ActiveSheet
  10.         xlButton = xlSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
  11.             Link:=False, DisplayAsIcon:=False, Left:=30, Top:=20, Width:=72, Height:=24)
  12.         xlButton.Name = "BtnTest"
  13.         xlButton.Object.Caption = "Press"
  14.         With xlBook.VBProject.VBComponents.Item(xlSheet.CodeName).CodeModule
  15.             iStartLine = .CreateEventProc("Click", "BtnTest") + 1
  16.             .InsertLines(iStartLine, "Msgbox ""Hi""")
  17.         End With
  18.         xlApp.VBE.MainWindow.Visible = False
Mar 9 '07 #2
Thanks for your help SammyB your code help me a lot
Jun 15 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Jeff | last post by:
I will start off by giving you a background of the process I am taking. The nature of my DTS package is that I recieve an Excel Spreadsheet, run it through the DTS Package applying validation to...
by: fumihiko | last post by:
Hi, I created an activex control (C++), and it uses another COM dll (C++). This COM dll links with a static library that dose some calculation. (both are debug multithreaded dll) I created a...
by: EJ1003 | last post by:
Hello I would like to create Activex Control uisng C# and use it in ASP.Net webform. User Control is not solving my requirement so I am going for Activex Control. Please guide me on this, how...
by: Steve Richter | last post by:
running a simple vbscript in an .htm page that starts excel and loads the spreadsheet with the contents of a <table> ... </table> getting an "Error: ActiveX component cant create object....
by: Rich Ulichny | last post by:
Not sure if this is correct newsgroup but I figured I had to start somewhere. We need to build a Web based application to allow users to choose an Excel file from their hard drive (or other...
by: qualitynice | last post by:
HELP :-)... I'm creating an embedded activex object in an asp.net page using the HtmlGenericControl class. I'm doing this because when I tried to embed it directly in the aspx page, it stopped...
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
by: done1105 | last post by:
Using VB.net, i want to dynamically create a workbook and add a command botton to one of the sheets. how would i do this? I see examples using VBA but i am not able to translate them to Vb.net....
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.