excel-vba

runtime error "out of memory"+excel macro

hi experts. i have one macro,which i called when cell change. this macro select images and delete them and insert another image depending on cell value using following code. i have same code for two sheets. Private Sub Worksheet_SelectionChange(ByVal Target As Range) ActiveSheet.Shapes.SelectAll Selection.Delete 'insert imag...

Reduce the file size of Excel

Hi, I'm working in an excel application and providing a menu to the user to add a new worksheet in that excel application (Excel Workbook). The worksheet will be added once the user clicks the "OK" button and I'm using a template to add this worksheet (The template has lot of formatting and formulas in it) Lets say the file size is 10 ...

Excel I have a .Net object compiled as a tlb but cant not access any methods apart from Dispose.

Hi This is ongoing issue to something I posted yesterday. I have a .net object that I want to use in Excel. I have an existing VBA script that i need to alter to call this the object from. I have then converted the object to a TLB. I've not really touched on this area before so any help will be appreciated. I have created an interfac...

IF Statement in VBA

Private Sub sendemail(esubj) Sheets("Actual").Select myfridate = Cells(1, 3).Value myfridate = DateAdd("d", -2, myfdate) myfridate = Format(myfridate, "mm-dd-yy") Sheets("Actual").Select mysatdate = Cells(1, 3).Value mysatdate = DateAdd("d", -1, myfdate) mysatdate = Format(mysatdate, "mm-dd-yy") If Wee...

Timer functions and generating events with a callback

I need a better way of raising events than the SetTimer API in user32.dll. Have you used the other timer APIs successfully? Do you know another way of raising events or calling a function asynchronously in Excel? What do I mean by 'better'? I need something that can pop messages off of an internally-maintained queue, asynchronously. Th...

Excel assign copied sheet name as variable

I'm trying to copy an existing sheet in my workbook and then I want to use the copied sheet to run the rest of my code. (Sheet3 is the existing sheet, S_Temp is the copied sheet) Dim s_Temp as string Sheet3.copy Activesheet.name = S_Temp Sheets("S_Temp").Range("A1").value = "Test" How can I reference to the copied sheet? ...

Consolidating Columns in Excel

I have two columns in excel like the following a,apple a,bannana a,orange a,plum b,apple b,berry b,orange b,grapefruit c,melon c,berry c,kiwi I need to consolidate them like this on a different sheet a,apple,bannana,orange,plum b,apple,berry,orange,grapefruit c,melon,berry,kiwi Any help would be appreciated This code works...

casting BSTR as char* in a dll; different results depnding on VB/C# caller.

I have a dll function that takes BSTR parameters. These are casted as char* before being used for other things. When the dll is called from VB code this works fine. However, when it is called from C# code, only the first character is pointed to. Both of these are excel addIns for Pre-2007 and 2007+ versions of Office, which call into a...

vba: get unique values from array

is there built in functionality in vba to get unique values from a one-dimensional array? what about just getting rid of duplicates? if not, then how would i get the unique values from an array? ...

Return Empty String as NULL

I have a listbox select and I want when the user selects null for the empty string it produces to pull the nulls from the SQL table. Here's what I have now. Blank strings return nothing because there are no empty fields in the table. SELECT * FROM dbo.Table WHERE ID = " & TextBox2.Text & " and And Field1 IN (" & Msg1 & ") How do I co...

Pass a range into a custom function from within a cell

Hi I'm using VBA in Excel and need to pass in the values from two ranges into a custom function from within a cell's formula. The function looks like this: Public Function multByElement(range1 As String, range2 As String) As Variant Dim arr1() As Variant, arr2() As Variant arr1 = Range(range1).value arr2 = Range(range2).va...

Fill New Sheets With Data From Other Sheets

I have a master sheet that has rows of house address data, one column of which is a "State" column. I have 50 other sheets in the same document, corresponding to each of the 50 USA states. What I want to happen: When I enter an address in the master sheet, and enter a state (say "CA" or "California"), I want it to automatically populate ...

Excel VBA / SQL Union

Hi, I am trying to Join 2 separate columns from 2 different sheets to make a longer column from which i can then use a Vlookup from. Sheet1 A, B, C, D, E, F, G Sheet2 A, B, C, D, E, F, G I want to Join(Union) Columns B from sheet1 and C from sheet2 together and find the Distinct values of the new list. I have been working on this f...

Only allow users on my network domain to open an Excel workbook

Rather than distribute a password to employees, I would like to protect an excel workbook so that only users on the company domain can open the workbook. Is there a feasible way to do this? The workbook should be encrypted, but transparently decrypted for users who are logged into the company domain. That way, a file that strays from ...

Formatting line colour on an XY Scatter Graph using Excel 2007 VBA

Hi I have a procedure in Excel 2007 VBA that formats the colours of the lines on an XY Scatter graph according to the number of series in the graph. The part that I'm having trouble with is: With oSeries.Format.Line .ForeColor.ObjectThemeColor = rngColours.Cells(x, intSeries).Interior.ThemeColor .ForeColor.TintAndShade = rngCo...

If/Then in SQL Embedded in VBA

I've got a string like this in my Excel VBA: strSQL = "SELECT * FROM Total WHERE (SimulationID = (" & TextBox1.Text & ") And Test1 = (" & Example & "))" However, sometimes Test will be 'is null', which makes the query And Example = is NULL How can I change it to add an if/then statement or something to make it say And Example is ...

Call VSTO code from copied sheets

Hello, I'm currently considering to rewrite an Excel 2003 workbook that has VBA code in it to VSTO. This workbook contains multiple sheets. Each site has a visible button at the top of sheet. When the user clicks the button, it uses the data from some named cells as a parameter to retrieve data from a database and populate several tabl...

Need to open to two excel files and add numbers from them into a third file using vba.

I have two excel files which has similar formatting and the data map each other from cell b15:h31. Row 15 is heading and so is the column B. I want to read file1 cell by cell and add that cell's content to the corresponding cell in File 2 i.e C16 in file 1 gets added to C16 in file 2, C17 in file 1 to C17 in file 2 and so on. The output ...

How can I detect the results of Conditional Formating using VBA?

I have an excel file that has conditional formating set up to put a check or an x in a cell. How can I create an if statement that will detect which is in there without using the original conditioning formulas? ...

compare two excel sheets

how do you compare two excel sheet and determine which column is missing? (would like to compare a list of countries from sheet A with sheet B, then mark which country is missing) Note: they are in random order. ...