Dim objApp As Object Dim objBook As Object Dim objBooks As Object Dim objSheets As Object Dim objSheet As Object Dim range As Object ' Instantiate Excel and start a new workbook. objApp = CreateObject("Excel.Application") objBooks = objApp.Workbooks objBook = objBooks.Add objSheets = objBook.Worksheets objSheet = objSheets.Item(1) range = objSheet.Range("A1") 'Set the range value. range.Value = "Hello, World!" 'Return control of Excel to the user. objApp.Visible = True objApp.UserControl = TrueIf you wanted to not set Option Strict Off, then you need to use Reflection to have the code compile. This is how it is done in C#. Here is the same functionality as above but using Reflection and keeping Option Strict On:
Dim objApp_Late As Object Dim objBook_Late As Object Dim objBooks_Late As Object Dim objSheets_Late As Object Dim objSheet_Late As Object Dim objRange_Late As Object Dim Parameters() As Object Try ' Get the class type and instantiate Excel. Dim objClassType As Type objClassType = Type.GetTypeFromProgID("Excel.Application") objApp_Late = Activator.CreateInstance(objClassType) 'Get the workbooks collection. objBooks_Late = objApp_Late.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, Nothing, objApp_Late, Nothing) 'Add a new workbook. objBook_Late = objBooks_Late.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, Nothing, objBooks_Late, Nothing) 'Get the worksheets collection. objSheets_Late = objBook_Late.GetType().InvokeMember("Worksheets", BindingFlags.GetProperty, Nothing, objBook_Late, Nothing) 'Get the first worksheet. Parameters = New Object(0) {} Parameters(0) = 1 objSheet_Late = objSheets_Late.GetType().InvokeMember("Item", BindingFlags.GetProperty, Nothing, objSheets_Late, Parameters) 'Get a range object that contains cell A1. Parameters = New Object(1) {} Parameters(0) = "A1" Parameters(1) = Missing.Value objRange_Late = objSheet_Late.GetType().InvokeMember("Range", BindingFlags.GetProperty, Nothing, objSheet_Late, Parameters) 'Write "Hello, World!" in cell A1. Parameters = New Object(0) {} Parameters(0) = "Hello, World!" objRange_Late.GetType().InvokeMember("Value", BindingFlags.SetProperty, Nothing, objRange_Late, Parameters) 'Return control of Excel to the user. Parameters = New [Object](0) {} Parameters(0) = True objApp_Late.GetType().InvokeMember("Visible", BindingFlags.SetProperty, Nothing, objApp_Late, Parameters) objApp_Late.GetType().InvokeMember("UserControl", BindingFlags.SetProperty, Nothing, objApp_Late, Parameters) Catch theException As Exception Dim errorMessage As [String] errorMessage = "Error: " errorMessage = [String].Concat(errorMessage, theException.Message) errorMessage = [String].Concat(errorMessage, " Line: ") errorMessage = [String].Concat(errorMessage, theException.Source) MessageBox.Show(errorMessage, "Error") End Try>>Hi Rick,
>>>>>>> >>>>>>>Dim wrdDoc As Word.Document >>>>>>>Dim wrdApp As Word.Application >>>>>>>Dim strLargEnvTemplate as String = "C:\EnvTemplate.doc" >>>>>>> >>>>>>>wrdApp = CType(CreateObject("Word.Application"), Word.Application) >>>>>>>wrdApp.Visible = True >>>>>>> >>>>>>>wrdDoc = wrdApp.Documents.Open(strLargEnvTemplate) >>>>>>> >>>>>>>>>>>>>>
>>>>>>> >>>>>>>wrdDoc = wrdApp.Documents.Open(strLargEnvTemplate) >>>>>>> >>>>>>>'The error message is "Object Reference not set to instance of an object" >>>>>>> >>>>>>>'Word is instantiated OK - but the document will not load... >>>>>>>>>>>>>>