473,387 Members | 1,606 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,387 software developers and data experts.

Access VBA From In C# Code

33
I have an excel file with a customized command button, named "Credit Matrix", the click of the button shows a VBA from like the picture below. What i need is to populate the textfields and comboboxes of the VBA from and click on the "ok" button. I tried the following to access the VBA from, but i failed..... :(

Expand|Select|Wrap|Line Numbers
  1.             Excel.Application xlApp;
  2.             Excel.Workbook xlBook;
  3.             Excel.Worksheet xlSheet1, xlSheet2, xlSheet3;
  4.             xlApp = new Excel.Application();
  5.             xlApp.Visible = true;
  6.             xlBook =
  7.                 xlApp.Workbooks.Open(
  8.                     @"excelPath", 3,
  9.                     false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, Missing.Value, false);
  10.             CommandBar oCommandBar = xlApp.CommandBars["Worksheet Menu Bar"];
  11.             StringBuilder sb = new StringBuilder();
  12.             try
  13.             {
  14.                 for (var i = 1; i < xlApp.CommandBars.Count; i++)
  15.                 {
  16.                     var o = oCommandBar.Controls[i];
  17.                     if (o.Caption.IndexOf("Credit Matrix") >= 0)
  18.                     {
  19.                         CommandBarButton b = o.get_accChild("1") as CommandBarButton;
  20.                         b.Execute();
  21.                         break;
  22.                     }
  23.                 }
  24.             }
  25.             catch
  26.             {
  27.                 xlApp.Quit();
  28.             }
  29.             UserForm form;
  30.             Microsoft.Vbe.Interop.Forms.Control c;
  31.             foreach (VBComponent mod in xlBook.VBProject.VBComponents)
  32.             {
  33.                 sb.AppendLine(mod.Type.ToString());
  34.                 if (mod.Type.ToString() != "vbext_ct_MSForm") continue;
  35.                 form = (UserForm)mod.Designer; //gives null
  36.                 for (int i = 1; i < form.Controls.Count; i++)
  37.                 {
  38.                     c = (Microsoft.Vbe.Interop.Forms.Control)form.Controls.Item(i); // to fetch the controls of the form
  39.                 }
  40.             }
Pls help to get the from control and its child controls... Thanks
Attached Images
File Type: jpg untitled.jpg (8.4 KB, 116 views)
Jul 20 '10 #1
0 1079

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

Similar topics

2
by: Robin Lewis | last post by:
I have a simple Access database set up and a form and I need to compare two textboxes, 'email1' and 'email2', on the form. If the two textboxes do NOT match I need to change the background colour...
1
by: nickel | last post by:
I can access Microsoft Access database via ODBC on Windows 2000 using C++. Now, I would like to use the SAME piece of code to access MS SQL on Windows. Can I achieve this without any modification...
2
by: nickel | last post by:
I can access Microsoft Access database via ODBC on windows 2000 using C++ . Now, I would like to use the SAME piece of code to access MS SQL on Windows. Can I achieve this without any...
1
by: Rocky A | last post by:
I need to open an excel workbook and import info to my access program. That isn't the problem, I've got the code down for doing what I want to do. I'm declaring the variable and setting it like...
4
by: hendafe | last post by:
I have a problem of removing '/' in Access. I have a field with this record BD/02/1234. I want to automatically remove the '/' and save it in a new field record for another purpose. Presently...
1
by: Eugene | last post by:
Hi, Is there any tools in VBA / Access that allow to format/align the code. ( not "Ident" button on the toolbar ) As an example: Before formatting: IF ELSE END IF
6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
2
by: Vinayak Raghuvamshi | last post by:
I have a file that has been created using shared read/write access. But C# code never is able to open this file for read and keeps throwing "...cannot open file as it is being used by another...
3
by: italia | last post by:
I have a database with 2 columns and more than million rows. The first column is the id Example of the data (2 columns)- 04731 CRM 04731 CRM 04731 CRM 04731 RVB 04731 RVB
10
by: Stefan Weber | last post by:
Hi, I'm trying to access the JavaScript code contained in a <scripttag via its "text" attribute. This works well, if the code is embedded in the HTML page. However, when the code is in an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.