Open Excel


Home           Programming       Favorites      

This procedure is for use in Expression Web or Word.  It opens a new instance of Excel for use in those applications.

You must first have a reference set to the Microsoft Excel 12.0 Object Library.  If you have an older version of Excel installed, it may refer to 11.0 or 10.0.

First place the following code at the top of a module.
Public objExcel As Excel.Application
Public objWorkBook As Excel.Workbook
Public objWorksheet As Excel.Worksheet
Public objRange As Excel.Range			

The lines above will make the four objects available in any module or UserForm in your project.

The function below will return True if a new instance of Excel is created. 
Function OpenExcel() _
As Boolean
   On Error Resume Next
   OpenExcel = False
   Err.Clear
   Dim strNewName As String

   Set objExcel = GetObject(, "Excel.Application")
   If Err.Number <> 0 Then
      Set objExcel = New excel.Application
      Err.Clear
   End If
   'Make it visible
   objExcel.Visible = True
   'Turn off Exccel Alert messages
   objExcel.DisplayAlerts = False

   OpenExcel = True
   Exit Function

errHandler1:
   MsgBox "OpenExcel has failed", _
   vbCritical, "FunctionFailure"

End Function