excel-vba

Programmatically set "Select objects" cursor in Excel

I'm struggling to find out how to programmatically enable the "Select objects" cursor type. I checked the object browser and expected to find a property like Application.CursorType or Application.DrawingMode. Changing the cursor type isn't picked up in the macro recorder and I must be searching for the wrong terms as I can't find infor...

VBA - How do I remove a file from the recent documents list in excel 2007?

The recent documents feature in Office is really useful, but I moved a file to a new directory and now I can't get Excel to stop hitting me with a "can't find this file" notification whenever I open a workbook. The Excel options seem only to control how many of these "recent documents" are displayed and not how many are actually saved. ...

How do i save code changes to an Excel VBA add-in?

I've made an add-in for Excel in VBA and now I need to make changes to the code, but the file won't save. I open the .xlam file, I make the changes, ctrl-S to save with no errors popping up, close down. But when I reopen, none of the change I made are there. What gives? is there some special way I have to save an add-in to make change...

Coding Text Filters in Excel 2007

I am trying to use code to filter a spreadsheet dynamically, based on the current date. I am storing the date I need to filter on as "CurrDay" and I'm attempting to recall that stored date back into my filter algorithm. It is not working and I need to figure out how to do this to finish up this code. Everytime I run the code it retu...

What Excel VBA actions are possible on hidden worksheets or workbooks?

Hidden worksheets/workbooks have some limitations to what can be done in VBA code, like most Select and Selection statements, and anything coming from ActiveSheet, but I can't seem to find any list of what the limitations are. Google, the built-in documentation in the help system, and MSDN's website have all failed me. Can anyone point...

When I try to use a VBA function that I've defined in an Excel spreadsheet, I get "That is not a valid function"

I defined a function in VBA as follows Public Fuction Distance(X, Y) as Double Then in a cell i try to use the fuction. I type "@Dis" and get the drop down menu, select the function and then enter the parameters ending up with @Distance(A1, A2) in the cell. When I press Enter I get the Error "That function is not valid". I enabled ...

Can't add to a Double type

I have a double value I would like to increment, using the following snippet: Total = CDbl(Total + CDbl(Workbooks(1).Worksheets(1).Cells(1,1).Value)) The code continuously returns a type mismatch error, even though the cell it points to has a decimal value in it. What am I doing wrong? ...

Why is my KML Google Earth location printing off screen?

I am using this code to make a KML file: Sub Create_KML() ' Builds KML from spread sheet ' Keyboard Shortcut: Ctrl+c ' 'Trash = Application _ ' .GetOpenFilename("Text Files (*.txt), *.txt") 'Open File For Random As #1 ' "c:\Users\mwilson\Desktop\Trash.txt 'Open "c:\Users\mwilson\Desktop\Test Google\Trash.txt" For Output As #1 Open "C...

I need code to copy between two rows and paste into the another sheet with our giving any values?

For eg: I have 50 rows of data. In that 1st row is having names of the students. I need the code to copy the data from RAM to RAMESH. In between I have 20 rows. I need the code to copy the rows and paste the same into another sheet. And It should not ask me for the names. By default, it has to take the names as RAM & RAMESH. ...

How to handle modal UserForms?

I have a UserForm with ShowModal set True. I want to use the dialog as a form and as a progress bar, so after the user clicks "OK", the form should remain on-screen but code should continue to execute in the background. What's the best way to go about doing this? Currently, I have two forms, one where the user enters data, and then ...

Make Macro to input data into Excel spreadsheet

I am using Excel 2003 and I need to create a macro the asks the user for 5 inputs: Date, Project#, Fault, Problem, and Solution. I have never used macros before so I have no idea how to code this. Once the data is entered by the user I want it to go under the appropriate columns. After this is done the macro will not prompt the user for ...

VBA introductory book for non programmer recommendation

A coleague of mine has shown interest in learning a little about vba scripting. Unfortunatelly, I don't have time to show her, and even if I did, I'm horrible at explaining things to people. Can you recommend a good VBA book for someone who's never done any programming, that is, has a nice easy approach with lots of examples ? I've chec...

IFDEF equivalent in VBA

I have code that needs to run on both Excel 2003 and Excel 2007, and there are a few spots where changes in the versions cause the code to halt. I tried separating these lines out with If-Else statements, but the code won't compile on either because it doesn't recognize the code used for the other. Is there any way I could tell one ver...

Create a SQL Table from Excel VBA

The problem is that I cannot get the table name that was entered into the variable, "tblName", to be used instead I get a correctly named database with a table named "tblName". Is there some way to pick up the name in "tblName" or some way to change the name once it is created with a name th user enters? Private Sub CreateDatabaseFrom...

Excel: string parsing VBA

I would like to parse a cell column of strings in Excel VBA, each of the cell contains the following: 2 '␂' I would like to change the contents of this cell to contain only 2 (or any numeric characters just before the 'string'. What would be the easiest method of parsing such info? Thanks. ...

Multiple Pivot Charts SetSourceData Error

I have multiple pivot charts each with their own pivot table on separate worksheets in Excel 2002. When I try to generate these charts with VBA with the following code: Set cht = Charts.Add(After:=Worksheets("Setup")) With cht ' we use named ranges here .SetSourceData Source:=range(tblName) .Name = chtName .... where tb...

Default value for PivotChart Report Filter/Page Field

I'm generating a pivot chart in Excel 2002 with a macro, using a date field as the chart report filter (setting the field orientation to xlPageField). I would like to set the default selected value of this pivotfield to the most recent value in the date field. What's the right syntax for doing that in VBA? ...

excel vba - footers

I need to write a VBA code to copy a company logo in the headers/footers of one excel sheet to another sheet in another workbook. Any ideas? Thanks, Jill ...

Can't assign macro in excel

I am having some trouble with macros in my excel workbook. I have a couple of auto-shapes on one of my sheets which are grouped together for drawings. 2 of these have macros assigned to them (as 'kitchen - 1.xls'!but59 and 'kitchen - 1.xls'!but60), but I can't seem to assign macros to the other 2 shapes. I have tried right clicking on...

Variable number of arguments in ParamArray ArgList()

If I want to pass a number of values for the ParamArray arglist via an array, how do I do it? From what I've read so far, on VBA, it appears that I need to explicitly list the values that I want to pass. But what if there are potentially different numbers of values to pass, so I do not know in advance how many I'll want to pass to the fu...