How to use Excel class Application

The class Application represents the entire Microsoft Excel application. The Application object contains application-wide settings and options and methods that return top-level objects, such as ActiveCell, ActiveSheet, and so on. This page provides code for the methods of the Excel class Application: AddCustomList, ActivateMicrosoftApp, Calculate, CalculateFull, CalculateFullRebuild, CalculateUntilAsyncQueriesDone, CentimetersToPoints, CheckAbort, CheckSpelling, ConvertFormula, DDEExecute, DDEInitiate, DDEPoke, DDERequest, DDETerminate, DeleteCustomList, DisplayXMLSourcePane, DoubleClick, Evaluate, ExecuteExcel4Macro, FindFile, GetCustomListContents, GetCustomListNum, GetOpenFilename, GetPhonetic, GetSaveAsFilename, Goto, Help, InchesToPoints, InputBox, Intersect, MacroOptions, MailLogoff, MailLogon, OnKey, OnRepeat, OnTime, OnUndo, Quit, RecordMacro, RegisterXLL, Repeat, Run, SendKeys, SharePointVersion, Undo, Union, Volatile, Wait.

menu

AddCustomList Application

Adds a custom list for custom autofill and/or custom sort.


Application.AddCustomList ListArray:= 

Arguments

ListArray Specifies the source data as either an array of strings or a Range object.
ByRow Only used if ListArray is a Range object. True to create a custom list from each row in the range. False to create a custom list from each column in the range. If this argument is omitted and there are more rows than columns (or an equal number of rows and columns) in the range Microsoft Excel creates a custom list from each column in the range. If this argument is omitted and there are more columns than rows in the range Microsoft Excel creates a custom list from each row in the range.

ActivateMicrosoftApp Application

Activates a Microsoft application. If the application is already running, this method activates the running application. If the application isn't running, this method starts a new instance of the application.


Application.ActivateMicrosoftApp Index:= 

Arguments

Index Specifies the Microsoft application to activate.

Calculate Application

Calculates all open workbooks, a specific worksheet in a workbook, or a specified range of cells on a worksheet, as shown in the following table.


Application.Calculate 

CalculateFull Application

Forces a full calculation of the data in all open workbooks.


Application.CalculateFull 

CalculateFullRebuild Application

For all open workbooks, forces a full calculation of the data and rebuilds the dependencies.


Application.CalculateFullRebuild 

CalculateUntilAsyncQueriesDone Application

Runs all pending queries to OLEDB and OLAP data sources.


Application.CalculateUntilAsyncQueriesDone 

CentimetersToPoints Application

Converts a measurement from centimeters to points (one point equals 0.035 centimeters).


Dim dbl As Double 
dbl = Application.CentimetersToPoints(Centimeters:= )

Arguments

Centimeters Specifies the centimeter value to be converted to points.

CheckAbort Application

Stops recalculation in a Microsoft Excel application.


Application.CheckAbort 

Arguments

KeepAbort Allows recalculation to be performed for a Range.

CheckSpelling Application

Checks the spelling of a single word.


Dim boo As Boolean 
boo = Application.CheckSpelling(Word:= )

Arguments

Word The text whose spelling is to be checked.
CustomDictionary Either an expression that returns a Dictionary object or the file name of the custom dictionary.
IgnoreUppercase True if capitalization is ignored. If this argument is omitted the current value of the IgnoreUppercase property is used.

ConvertFormula Application

Converts cell references in a formula between the A1 and R1C1 reference styles, between relative and absolute references, or both.Variant.

 
Dim str as String
str = Application.ConvertFormula(Formula:= ,FromReferenceStyle:= )

Arguments

Formula A string that containis the formula you want to convert. This must be a valid formula and it must begin with an equal sign.
FromReferenceStyle The reference style of the formula.
ToReferenceStyle A constant ofXlReferenceStyle specifying the reference style you want returned. If this argument is omitted the reference style isn't changed; the formula stays in the style specified byFromReferenceStyle.
ToAbsolute A constant ofXlReferenceStylewhich specifies the converted reference type. If this argument is omitted the reference type isn't changed.
RelativeTo A Range object that contains one cell. Relative references relate to this cell.

DDEExecute Application

Runs a command or performs some other action or actions in another application by way of the specified DDE channel.


Application.DDEExecute Channel:= ,String:= 

Arguments

Channel The channel number returned by the DDEInitiate method.
String The message defined in the receiving application.

DDEInitiate Application

Opens a DDE channel to an application.


Dim lng As Long 
lng = Application.DDEInitiate(App:= ,Topic:= )

Arguments

App The application name.
Topic Describes something in the application to which you're opening a channel - usually a document of that application.

DDEPoke Application

Sends data to an application.


Application.DDEPoke Channel:= ,Item:= ,Data:= 

Arguments

Channel The channel number returned by the DDEInitiate method.
Item The item within a DDE topic to which the specified data is to be sent.
Data The data to be sent to the receiving application (the DDE server).

DDERequest Application

Requests information from the specified application. This method always returns an array.


Dim var As Variant 
var = Application.DDERequest(Channel:= ,Item:= )

Arguments

Channel The channel number returned by the DDEInitiate method.
Item The item to be requested.

DDETerminate Application

Closes a channel to another application.


Application.DDETerminate Channel:= 

Arguments

Channel The channel number returned by the DDEInitiate method.

DeleteCustomList Application

Deletes a custom list.


Application.DeleteCustomList ListNum:= 

Arguments

ListNum The custom list number. This number must be greater than or equal to 5 (Microsoft Excel has four built-in custom lists that cannot be deleted).

DisplayXMLSourcePane Application

Opens the XML Source task pane and displays the XML map specified by the XmlMap argument.


Application.DisplayXMLSourcePane 

Arguments

XmlMap The XML map to display in the task pane.

DoubleClick Application

Equivalent to double-clicking the active cell.


Application.DoubleClick 

Evaluate Application

Converts a Microsoft Excel name to an object or a value.


Dim var As Variant  
var = Application.Evaluate(Name:= )

Arguments

Name A formula or the name of the object using the naming convention of Microsoft Excel. The length of the name must be less than or equal to 255 characters.

ExecuteExcel4Macro Application

Runs a Microsoft Excel 4.0 macro function and then returns the result of the function. The return type depends on the function.


Application.ExecuteExcel4Macro String:= 

Arguments

String A Microsoft Excel 4.0 macro language function without the equal sign. All references must be given as R1C1 strings. If String contains embedded double quotation marks you must double them. For example to run the macro function =MID(sometext 1 4) String would have to be MID(sometext 1 4).

FindFile Application

Displays the Open dialog box.


Dim boo As Boolean 
boo = Application.CheckSpelling(Word:= ) 
boo = Application.FindFile()

GetCustomListContents Application

Returns a custom list (an array of strings).


Application.GetCustomListContents ListNum:= 

Arguments

ListNum The list number.

GetCustomListNum Application

Returns the custom list number for an array of strings. You can use this method to match both built-in lists and custom-defined lists.


Dim lng As Long  
lng = Application.GetCustomListNum(ListArray:= )

Arguments

ListArray An array of strings.

GetOpenFilename Application

Displays the standard Open dialog box and gets a file name from the user without actually opening any files.


Application.GetOpenFilename 

Arguments

FileFilter A string specifying file filtering criteria.
FilterIndex Specifies the index numbers of the default file filtering criteria from 1 to the number of filters specified in FileFilter. If this argument is omitted or greater than the number of filters present the first file filter is used.
Title Specifies the title of the dialog box. If this argument is omitted the title is Open.
ButtonText Macintosh only.
MultiSelect True to allow multiple file names to be selected. False to allow only one file name to be selected. The default value is False.

GetPhonetic Application

Returns the Japanese phonetic text of the specified text string. This method is available to you only if you have selected or installed Japanese language support for Microsoft Office.


Dim str As String  
str = Application.GetPhonetic()

Arguments

Text Specifies the text to be converted to phonetic text. If you omit this argument the next possible phonetic text string (if any) of the previously specified Text is returned. If there are no more possible phonetic text strings an empty string is returned.

GetSaveAsFilename Application

Displays the standard Save As dialog box and gets a file name from the user without actually saving any files.


Application.GetSaveAsFilename 

Arguments

InitialFilename Specifies the suggested file name. If this argument is omitted Microsoft Excel uses the active workbook's name.
FileFilter A string specifying file filtering criteria.
FilterIndex Specifies the index number of the default file filtering criteria from 1 to the number of filters specified in FileFilter. If this argument is omitted or greater than the number of filters present the first file filter is used.
Title Specifies the title of the dialog box. If this argument is omitted the default title is used.
ButtonText Macintosh only.

Goto Application

Selects any range or Visual Basic procedure in any workbook, and activates that workbook if it is not already active.


Application.Goto 

Arguments

Reference The destination. Can be a Range object a string that contains a cell reference in R1C1-style notation or a string that contains a Visual Basic procedure name. If this argument is omitted the destination is the last range you used the Goto method to select.
Scroll True to scroll through the window so that the upper-left corner of the range appears in the upper-left corner of the window. False to not scroll through the window. The default is False.

Help Application

Displays a Help topic.


Application.Help 

Arguments

HelpFile The name of the online Help file you want to display. If this argument isn't specified Microsoft Excel Help is used.
HelpContextID Specifies the context ID number for the Help topic. If this argument isn't specified the Help Topics dialog box is displayed.

InchesToPoints Application

Converts a measurement from inches to points.


Dim dbl As Double 
dbl = Application.InchesToPoints(Inches:= )

Arguments

Inches Specifies the inch value to be converted to points.

InputBox Application

Allows the user to specify what value or range to work with (follow link for details)

Intersect Application

Returns a Range object that represents the rectangular intersection of two or more ranges.


Dim rng As Range  
Set rng = Application.Intersect(Arg1:= ,Arg2:= ,... )

Arguments

Arg1, Arg2, ... The intersecting ranges. At least two Range objects must be specified.

MacroOptions Application

Corresponds to options in the Macro Options dialog box. You can also use this method to display a user defined function (UDF) in a built-in or new category within the Insert Function dialog box.


Application.MacroOptions 

Arguments

Macro The macro name or the name of a user defined function (UDF).
Description The macro description.
HasMenu This argument is ignored.
MenuText This argument is ignored.
HasShortcutKey True to assign a shortcut key to the macro (ShortcutKey must also be specified). If this argument is False no shortcut key is assigned to the macro. If the macro already has a shortcut key setting this argument toFalse removes the shortcut key. The default value is False.
ShortcutKey Required if HasShortcutKey is True; ignored otherwise. The shortcut key.
Category An integer that specifies an existing macro function category (Financial Date and Time or User Defined for example). See the Remarks section to determine the integers that are mapped to the built-in categories. You can also specify a string for a custom category. If you provide a string it will be treated as the category name that is displayed in the Insert Function dialog box. If the category name has never been used a new category is defined with that name. If you use a category name that is the same as a built-in name (see list in Remarks section) Microsoft Excel will map the user defined function to that built-in category.
StatusBar The status bar text for the macro.
HelpContextID An integer that specifies the context ID for the Help topic assigned to the macro.
HelpFile The name of the Help file that contains the Help topic defined byHelpContextId.
ArgumentDescriptions A one-dimensional array that contains the descriptions for the arguments to a UDF that are displayed in the Function Arguments dialog box.

MailLogoff Application

Closes a MAPI mail session established by Microsoft Excel.


Application.MailLogoff 

MailLogon Application

Logs in to MAPI Mail or Microsoft Exchange and establishes a mail session. If Microsoft Mail isn't already running, you must use this method to establish a mail session before mail or document routing functions can be used.


Application.MailLogon 

Arguments

Name The mail account name or Microsoft Exchange profile name. If this argument is omitted the default mail account name is used.
Password The mail account password. This argument is ignored in Microsoft Exchange.
DownloadNewMail True to download new mail immediately.

OnKey Application

Runs a specified procedure when a particular key or key combination is pressed.


Application.OnKey Key:= 

Arguments

Key A string indicating the key to be pressed.
Procedure A string indicating the name of the procedure to be run. If Procedure is (empty text) nothing happens when Key is pressed. This form of OnKey changes the normal result of keystrokes in Microsoft Excel. If Procedure is omitted Key reverts to its normal result in Microsoft Excel and any special key assignments made with previousOnKey methods are cleared.

OnRepeat Application

Sets the Repeat item and the name of the procedure that will run if you choose the Repeat command after running the procedure that sets this property.


Application.OnRepeat Text:= ,Procedure:= 

Arguments

Text The text that appears with the Repeat command.
Procedure The name of the procedure that will be run when you choose the Repeatcommand.

OnTime Application

Schedules a procedure to be run at a specified time in the future (either at a specific time of day or after a specific amount of time has passed).


Application.OnTime EarliestTime:= ,Procedure:= 

Arguments

EarliestTime The time when you want this procedure to be run.
Procedure The name of the procedure to be run.
LatestTime The latest time at which the procedure can be run. For example if LatestTime is set to EarliestTime + 30 and Microsoft Excel is not in Ready Copy Cut or Find mode atEarliestTime because another procedure is running Microsoft Excel will wait 30 seconds for the first procedure to complete. If Microsoft Excel is not in Ready mode within 30 seconds the procedure won't be run. If this argument is omitted Microsoft Excel will wait until the procedure can be run.
Schedule True to schedule a new OnTime procedure. False to clear a previously set procedure. The default value is True.

OnUndo Application

Sets the text of the Undo command and the name of the procedure that is run if you choose the Undo command after running the procedure that sets this property.


Application.OnUndo Text:= ,Procedure:= 

Arguments

Text The text that appears with the Undo command.
Procedure The name of the procedure that's run when you choose the Undo command.

Quit Application

Quits Microsoft Excel.


Application.Quit 

RecordMacro Application

Records code if the macro recorder is on.


Application.RecordMacro 

Arguments

BasicCode A string that specifies the Visual Basic code that will be recorded if the macro recorder is recording into a Visual Basic module. The string will be recorded on one line. If the string contains a carriage return (ASCII character 10 or Chr$(10) in code) it will be recorded on more than one line.
XlmCode This argument is ignored.

RegisterXLL Application

Loads an XLL code resource and automatically registers the functions and commands contained in the resource.


Dim boo As Boolean   
boo = Application.RegisterXLL(Filename:= )

Arguments

Filename Specifies the name of the XLL to be loaded.

Repeat Application

Repeats the last user-interface action.


Application.Repeat 

Run Application

Runs a macro or calls a function. This can be used to run a macro written in Visual Basic or the Microsoft Excel macro language, or to run a function in a DLL or XLL.


Application.Run 

Arguments

Macro The macro to run. This can be either a string with the macro name a Range object indicating where the function is or a register ID for a registered DLL (XLL) function. If a string is used the string will be evaluated in the context of the active sheet.
Arg1, Arg2, ...  Any argument that should be passed to the function.

SendKeys Application

Sends keystrokes to the active application.


Application.SendKeys Keys:= 

Arguments

Keys The key or key combination you want to send to the application as text.
Wait True to have Microsoft Excel wait for the keys to be processed before returning control to the macro. False (or omitted) to continue running the macro without waiting for the keys to be processed.

SharePointVersion Application

Returns the version number of SharePoint Foundation instances running at site for the specified URL.


Dim lng As Long  
lng = Application.SharePointVersion(bstrUrl:= )

Arguments

bstrUrl The URL of site to check.

Undo Application

Cancels the last user-interface action.


Application.Undo 

Union Application

Returns the union of two or more ranges.


Dim rng As Range  
Set rng = Application.Union(Arg1:= ,Arg2:= )

Arguments

Arg1, Arg2, ... At least two Range objects must be specified.

Volatile Application

Marks a user-defined function as volatile. A volatile function must be recalculated whenever calculation occurs in any cells on the worksheet. A nonvolatile function is recalculated only when the input variables change. This method has no effect if it's not inside a user-defined function used to calculate a worksheet cell.


Application.Volatile 

Arguments

Volatile True to mark the function as volatile. False to mark the function as nonvolatile. The default value is True

Wait Application

Pauses a running macro until a specified time. Returns True if the specified time has arrived.


Dim boo As Boolean  
boo = Application.Wait(Time:= )

Arguments

Time The time at which you want the macro to resume in Microsoft Excel date format.

For more info see

Microsoft Office Object reference on Application