excel-vba

EXCEL VBA CSV Date format problem

I am an Excel VBA newbie. My apologies if I am asking what seems to be an obvious question. I have a CSV text file I am opening in an Excel worksheet. One row of the file contains date information formatted as "YY-MMM', (ie: 9-FEB, or 10-MAY). When the Excel spreadsheet opens the file the date information is changed to "mm/dd/yyyy" forma...

Return background color of selected cell

I have a spreadsheet which cells in are colored meaningfully. Does any body know how i can return the background color value of a current cell in Excel sheet? ...

How to Reverse the Order of a Selected Range of Excel Columns using VBA

I am new to VBA and am trying to figure out how to reverse the order of a selected range of columns without hard coding. Every example I look out either hard codes the columns to reverse the order of, or assumes you want to reverse all the columns in the worksheet. I'm not trying to ask someone to write this for me, but as simple as this...

One line macro

How can I write a one line macro to write two different words in cell A1 and A2? ...

How can I find user's time zone offset in excel

I am using an excel macro to generate an RSS feed. The user's timezone offset needs to go in the field of the RSS feed. How can I do this programatically in the excel macro function? ...

What does <> mean?

I have seen this before in SQL and VB, I am now reverse engineering an Excel speadsheet and have come across the following formula: =IF(D23<>0,"Insufficent",0) I am converting it to ActionScript: var result:String = [condition] ? 0 : "Insufficient"; but I am unsure of what D23 <> 0 means, is it simply "not equal"? ...

How can I have a VBA macro perform a Search/Replace in formulas across an entire workbook?

I distribute an Excel workbook to a number of users, and they are supposed to have a particular macro file pre-installed in their XLSTART folder. If they don't have the macro installed correctly, and they send the workbook back to me, any formulas depending on it include the full path of the macro, e.g.: 'C:\Documents and Settings\rich...

Is there a tactical (read 'hack') solution to avoid having the VBA code and Excel sheet as one binary file?

As I understand it when I create an Excel sheet with VBA code the VBA code is saved as binary with the sheet. I therefore can't put the code into source control in a useful way, have multiple devs working on the problems, diffing is difficult, etc. Is there a way round this without switching to VSTO, COM addins etc? E.g. for the sheet...

excel: charting with unknown number of data

Let's (for discussion purposes) say that I have x and y data in 2 columns. They're some measured data which, several times a day, a few of them are added (usually 4 times a day). Now, I wish to plot y=f(x) (linear scale), but the problem is since data is constantly added to determine the number of points which will go in the plot. Always...

Opening semicolon delimited CSV file with VBA in Excel 2000

How does one open a semicolon delimited CSV file with VBA in Excel 2000? In Excel 2003 11.8231.8221 SP3 with VBA 6.5.1025, I can open a semicolon delimited file with the following VBA code: Workbooks.OpenText filename:=myFilename, _ DataType:=xlDelimited, Semicolon:=True, Local:=True However, when the same code is run in Excel 20...

How can I return the results of a function to a cell in Excel?

Suppose I have a function attached to one of my Excel sheets: Public Function foo(bar As Integer) as integer foo = 42 End Function How can I get the results of foo returned to a cell on my sheet? I've tried "=foo(10)", but all it gives me is "#NAME?" I've also tried =[filename]!foo(10) and [sheetname]!foo(10) with no change. ...

Adding controls to a frame in an Excel userform with VBA

I need to create labels and buttons dynamically and then add them to a frame within a userform. How do I do this? Seems like it should be easier than it really is. ...

What causes Visual Basic Run-time error -2147319765 (8002802b) in Excel when an ActiveX control has been instanced?

I have created an ActiveX control using C++. I use Visual Basic code to instance the control in an Excel worksheet. I can only run the VB script once, subsequent runs cause the following runtime error when attempting to access the 'ActiveSheet' variable: Microsoft Visual Basic Run-time error '-2147319765 (8002802b)': Automation erro...

Excel VBA object constructor and destructor

I need to make some custom objects in VBA that will need to reference each other and I have a some issues. First - how do object constructors work in VBA? Are there constructors? Second - are there destructors? How does VBA handle the end of the object lifecycle? If I have an object that references others (and this is their only refere...

Open Excel file for reading with VBA without display

I want to search through existing Excel files with a macro, but I don't want to display those files when they're opened by the code. Is there a way to have them open "in the background", so to speak? ...

Macro to Insert Information Between Rows Repeatedly

I want to insert a list (below: generator, control tower, etc.) repeatedly throughout a spreadsheet. It should be inserted every other row (after each Turbine) and offset one column as shown below. I don't know how to write a macro to do this automatically. Any help is appreciated. TURBINE A-2 Generator Control Tower Brak...

Copy paste between my excel with macros and an another excel

I have disabled "cut" in my excel and have changed paste to paste-special (values) only in my function called "stoppaste". I have written this code in Workbook_Activate, Workbook_SheetActivate. The code is given below: Application.CellDragAndDrop = False Application.CommandBars("Edit").Controls("Paste").Enabled = False Application.Com...

Exporting VBA code from Multiple Excel documents to put into version control

Does anyone know a way to export the VBA code from a number of Excel documents, so that the code can be added into a subversion repository? Without having to manually open each document and export the code. ...

Why does my VBA project fail in other computers?

I made a VBA project based on Excel and Access. When I copied to other computers, some methods (left, right, etc) or controls (ComboBox) sometimes disabled. I had to rebuild in that computer. But sometimes it's OK. Why? Is that because of licence issues? ...

How can we use MSHTML with VBA?

I saw a lot of examples in MSDN on how to use MSHTML in VS. Have anyone known if and how we can use MSHTML and VBA to open web pages? Thanks. ...