Use the Application property to return the Application object. The following example applies the Windows property to the Application object.

VB

Application.Windows(“book1.xls”).Activate

The following example creates an Excel workbook object in another application and then opens a workbook in Excel.

VB

Set xl = CreateObject(“Excel.Sheet”)

xl.Application.Workbooks.Open “newbook.xls”


Many of the properties and methods that return the most common user-interface objects, such as the active cell (ActiveCell property), can be used without the Application object qualifier. For example, instead of writing:

VB

Application.ActiveCell.Font.Bold = True

You can write:

VB

ActiveCell.Font.Bold = True

VB

Sub Cbm_Value_Select()

‘Set up the variables.

Dim rng As Range

‘Use the InputBox dialog to set the range for MyFunction, with some simple error handling.

Set rng = Application.InputBox(“Range:”, Type:=8)

If rng.Cells.Count <> 3 Then

MsgBox “Length, width and height are needed -” & _

vbLf & “please select three cells!”

Exit Sub

End If

‘Call MyFunction by value using the active cell.

ActiveCell.Value = MyFunction(rng)

End Sub

 

Function MyFunction(rng As Range) As Double

MyFunction = rng(1) * rng(2) * rng(3)

End Function

Meny
Nettstedet er under arbeidI drift i løpet høsten 2019