excel-vba

Calling python code from VSTO excel addin

Hi, I am working on an excel2007 plugin in VSTO and am using VB for coding it. One of the item in the plugin is the button, pressing which should give a call to a python program which will add some data to the current worksheet. I would like to know 1 How can i call the python function from the VBA code 2 pass the active workbook to thi...

Getting the selected cell's range from a different worksheet in Excel

I'm trying to set up Excel so that the cell's value that is selected in the first worksheet is set to the value of a cell that's double clicked in a different worksheet. So far my code looks like this: Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim c As Range For Each c In Sheet1.Range("M11:M24...

Excel VBA Error when adding attachments using CDO.Message "Object doesn't support this property or method"

VBA/Excel Macro Programming - I'm trying to automate sending out an email with an Excel attachment. When I try and add an attachment, I get the following error: "Object doesn't support this property or method". Anyone have any ideas? It's not filename, filepath issues, the file exists, and the path is correct. Dim wbOld As Workbook D...

How can I programmatically freeze the top row of an Excel worksheet in Excel 2007 VBA?

I am looking to programmatically freeze the top row of an Excel worksheet from VBA. The end goal is to produce the same effect as the View > Freeze Panes > Freeze Top Row command in Excel 2007 so that the top row of the worksheet is frozen and users can see the top row of the worksheet even as they scroll through the data. ...

How to get the index of a combo box in Excel spreadsheet by using VBA?

Hi, I have an Excel 2003 file. In the first sheet, I put a combo box. After that, I assign a macro to handle the change event. The macro is located a module in the VB Editor's Project Explorer box. In the macro, I want to write some lines to get the index of the combo box's selected item index. What should I write? I wrote the line I...

How to convert a Variant array to a Range?

I have a 2D array of type Variant. The size and values that populate the array are generated based on data within a worksheet. Further processing is required on this array, the primary being the interpolation of several values. I am using this interpolation function ( I know about excel equivalent functions but a design choice was made n...

Trying to get data from sql server 2005 from excel macro

Hi I am trying to get data from sql server 2005 to excel.. I have written code in excel vba Below is my code Dim strConnection, conn, rs, strSQL strConnection = "Provider=sqloledb;Data Source=LEON7269-G09\SQLEXPRESS;Initial Catalog=test;User Id=sa;Password=sa@123;" Set conn = Server.CreateObject("ADODB.Connection") conn.Open strConn...

Using constructors on the Sub New() for a CCW

I'm trying to create a COM Class Library for my VBA Project and one of the limitations I've seemed to have stumbled across is using constructors on the New() subroutine. After creating the new COM class a Public Sub New() is created with the following comments ' A creatable COM class must have a Public Sub New() ' with no parameters, ...

Creating Batch File

I'm trying to create a batch file that will convert an Excel file to a PDF. Is there something wrong with my command line because it doesn't seem to work: Dim i As Double Dim sBatchFile As String ActiveWorkbook.Save sBatchFile = "C:\test.bat" Open sBatchFile For Output As #1 Print #1, "@ECHO OFF" Print #1, "ECHO Converting Excel...

Rating the straightness of a line

I have a data set that defines a set of points on a 2-dimensional Cartesian plane. Theoretically, those points should form a line, but that line may be perfectly horizontal, perfectly vertical, and anything in between. I would like to design an algorithm that rates the 'straightness' of that line. For example, the following data sets...

Excel Locked Cell Query

I want to allow the user to increase and decrease the decimal places of a locked cell in excel 2007 without allowing other formatting options. Can anyone tell me how to do this? ...

Excel VBA 2007: Select all sheets except for specified ones (to perform actions onto)

I'm trying to create a macro that selects most of the sheets in the workbook and then uses ExportAsFixedFormat to print them to PDF. The problem is, while I know the sheets I don't want to include, I don't know exactly which sheets will be in place in at given time, so I can't make a static list of "Select these sheets" (It'd probably b...

Excel CommandBars / Controls in local languages

Hello All, Win-XP / Excel 2003 / VBA .... I have the following piece of code to intercept all paste activities initiated by the user (main menu, context menu and control-V key) and send it to a Sub TrappedPaste() .... Application.CommandBars("Edit").Controls("Paste").OnAction = "TrappedPaste" Application.CommandBars("Edit").Controls("...

Getting the number of filled cells in a column (VBA)

Hi mates, I'm just starting with "programming" VBA on Excel to automatize some anoying manual stuff...so this will probebly sound like a total nooby question, although I'm not very familiar to VBA Objects and so on. So my quesstion: Is there a more elegant way to find out the length of a column? My first column is an index, with monoto...

Which property holds the items in the resultant Range of non-contiguous cells ?

I have used the Find_Range function from OzGrid which returns a Range object with the found items. It have used it successfully. I know that looping through each item of the resultant Range allows for updates/modifications to the individual cells. The Count property shows the right value. There is no Value property and the Value2 prope...

Connection to SQL

I want to add a connection to a sheet so that each time a cell is refreshed, a value is passed in from SQL. I want it to reference a textbox on one of the other sheets for where ID = How do I set the connection to refresh with that value. What do I put in my connection string? I can get it to work staticly. ...

Click button or execute JavaScript function with VBA

I'm trying to get my VBA routine to interact with a page that uses JavaScript, and have been successful in the past. After a recent update, it no longer works. At this point I need to either A) programmatically click a button or B) execute the function the button calls. The tricky part is that the button has no declared name. There a...

What are the events that I can use in Excel

Where can I find a list of events in Excel? I want to write macros in VBA based on them. I already know of Worksheet_BeforeDoubleClick, but I more or less just discovered that randomly/remembered it was used in Access. Does anyone have a complete list or know where I can find one of the different events in Excel? ...

Change both the code name and the shape name of an activex optionbutton control in Excel vba

Excel VBA: I am trying to get to some activex option buttons through the OLEObjects object, but I am finding that even though I change the value of (Name) in the property window for the object, it still requires the "OptionButton1" default name as a key. I know that some of the objects in Excel VBA have a code name and another name whic...

I receive a type-mismatch error from VBA on one computer, but not on others. Why?

Hi, I have an Excel file with macro. In this file, there is a user form. In the form, there is a Textbox. I call the user form "MyForm" and the TextBox "MyTextBox". I also have a module. In this module there is a subroutine like this Sub MySub(s As String) MyForm.MyTextBox.Value = s ... End Sub On most computers, the code ab...