473,766 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Shared addin for excel 2003, Can we add button on excel sheet

18 New Member
hi guys,

this is first posting on The Scripts network.
Guys,
i have built a shared addin for Excel 2003 using visual studio 2005 and C#. Till adding command bar and menu items, it was okay.

But now i want to add typical button on excel sheet programmaticall y, but nothing seems to working.
Is it possible that i can add typical button controls on excel sheet from program.
Apr 19 '07 #1
2 3596
SammyB
807 Recognized Expert Contributor
Should be possible. Here's how I did it in Excel VBA:
Expand|Select|Wrap|Line Numbers
  1. Sub aBook()
  2. 'This Macro creates a workbook, a button, and a code module
  3. Dim wb As Workbook
  4. Dim ws As Worksheet
  5. Dim s As Variant
  6. Dim btn As OLEObject
  7. Dim lLines As Long
  8. ' Hide VBE Window = No screen flashes
  9.     Application.VBE.MainWindow.Visible = False
  10. ' Create a new Workbook with one worksheet, Cmds
  11.     Set wb = Workbooks.Add
  12.     Set ws = Worksheets.Add
  13.     ws.Name = "Cmds"
  14.     Application.DisplayAlerts = False
  15.     For Each s In wb.Worksheets ' Delete the rest of the worksheets
  16.         If s.Name <> "Cmds" Then s.Delete
  17.     Next s
  18.     Application.DisplayAlerts = True
  19.  
  20. ' Create a button
  21.     Set btn = ws.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
  22.                 Left:=50, Top:=25, Width:=75, Height:=20)
  23.     btn.Name = "cmdWork"
  24.     btn.Object.Caption = "Press"
  25.  
  26. ' Find the associated code module and create the click event handler
  27.     For Each s In wb.VBProject.VBComponents
  28.         If s.Name = ws.CodeName Then
  29.             With s.CodeModule
  30.                 lLines = .CountOfLines
  31.                 .InsertLines lLines + 1, "Sub cmdWork_Click()"
  32.                 .InsertLines lLines + 2, "    MsgBox ""Back to Work!"""
  33.                 .InsertLines lLines + 3, "End Sub"
  34.             End With
  35.             Exit For
  36.         End If
  37.     Next s
  38. End Sub
Obviously, you have some translation to do.

But, I have had a lot of trouble trying to do the stuff you have already done. Can you outline the steps to creating the Addin with C# 2005? I want to add a dialog box. I could do it with VB6, but am stuck with .Net.
Apr 19 '07 #2
jesusdiehard
18 New Member
thanx frnd
its working, just need little translation.

As far as creating addin in C# is concerned,
there are two ways
1. VSTO addin
2. Shared addin

VSTO is future but still little still not support all office applications like access.

main steps for creating shared addin

1 .In the New Project dialog box, expand Other Projects under Project Types, select Extensibility Projects, and then select the Shared Add-in template.
2 . Type xyz as the name of the add-in and then click OK.
3. When the Extensibility Wizard appears, follow these steps:
4. select Create an Add-in using Visual C#, and then click Next.
5. select the any host applications, and then click Next:

Automatically it wil generate a lot of code for u.
The class of interest is Connect class

add following reference in connect class

using Core = Microsoft.Offic e.Core;
using Excel = Microsoft.Offic e.Interop.Excel ;
using System.Windows. Forms;

I have just given here is just abstract description


these are two links to gud one to start with
http://support.microso ft.com/default.aspx?sc id=kb;en-us;Q302901
http://msdn2.microsoft .com/en-us/library/aa663367.aspx

just reply if there is any problem
Apr 20 '07 #3

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

Similar topics

8
3034
by: Jaime Rios | last post by:
Hi, I created a COM AddIn for Word that performs the functions that it needs to, but I needed to add the ability for the toolbar created by the COM AddIn to remember it's last position and whether it was docked or not. I added the following code to my "OnConnection" function but it fails with an error, "Run-time exception thrown : System.IO.IOException - Bad file name or number." With applicationObject.CommandBars("SampleToolbar")
8
2860
by: DC Gringo | last post by:
I have a simple button that should open another window and export a datagrid to an Excel file. I'm getting: "Name 'window' is not declared." What do I need to declare or import? <INPUT ID="Button5" ONCLICK="Button5_Click" NAME="Button5" TYPE="button" VALUE="Export to Excel"> Sub Button5_Click()
12
3225
by: elziko | last post by:
I'm using late binding (I must) to automate Excel. My code opens Excel after createing and poulating some sheets. My problem is that when the user finally decides to close Excel its process is left running until my application closes. I have tried setting my Excel.Application object to Nothing. I have tried to then fore the GC into action using:
0
1923
by: maitrepoy | last post by:
Hello I have to create a small addin which works on Powerpoint, Word, Outlook, and Excel on Office 2000, XP, and 2003. This addin consists in adding 2 new Buttons in the "File" Menu of office. This is properly done, but the events which should be triggered with the button.click method are not triggered in Word. I don't understand because it properly works in the 3 others host applications. If someone has an issue, I would be most grateful....
0
2453
by: maitrepoy | last post by:
hello I have to create a small addin which works on Powerpoint, Word, Outlook, and Excel on Office 2000, XP, and 2003. This addin consists in adding 2 new Buttons in the "File" Menu of office. This is properly done, but the events which should be triggered with the button.click method are not triggered in Word. I don't understand because it properly works in the 3 others host applications. If someone has an issue, I would be most grateful....
4
2500
by: Nick Dreyer | last post by:
Is it possible to see public class variables of a COM addin in Excel 97 VBA? I have successfully created the (Visual Basic 2003 .NET) COM and referenced it in an Excel 97 VBA project. The VBA object browser sees - and the project otherwise successfully interacts with - all the COM addin methods and properties, but none of the public variables - target, init and size in the code below - can be accessed. When I reference the exact same...
18
8290
by: Frank M. Walter | last post by:
Hello, I have made an small AddIn with udf for excel 2003. I use vs2003. The point of view is the function __T() I call it in excel sheet writing =__T() I am not able to set a value to a given cell. region.Value2="qwe"; //bumm! A exception will be trown. On all PCs with excel. HRESULT 0x800A03EC
0
2021
by: Omer | last post by:
I am trying to create a shared addin using visual studio 2005 with the following code. It is working only in Power Point Appliction and not loading in Excel and Word I used the Visual Studio Wizard to create shared addin and seleted the Programs Power Point, Excel and Word. I am using the Office XP: imports Extensibility imports System.Runtime.InteropServices Imports Microsoft.Office.Core
4
3983
by: =?Utf-8?B?THluZXJz?= | last post by:
Hello All, We have a VB.NET application writen using VS 2003. This application apens an excel file from a vendor, reads the data and performs whatever functions it needs. We recently upgraded our sytems to Excel 2003 from Excel 2000. Our application started erroring out because it was having a problem with opening the Excel file. From troubleshooting, the exact problem is in Excel 2003, it does not like the sheet name (even though the...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.