Article ID: 163099
Article Last Modified on 9/13/2006
Sub From_Excel_To_Project()
'Sets the object variable to contain a Microsoft Excel Object.
Dim xlObj As Object
'Creates a string variable to temporarily store information.
Dim strVar As String
'Clears the xlObj object.
Set xlObj = Nothing
'Sets the xlObj object as a Microsoft Excel Application object.
Set xlObj = CreateObject("Excel.Application")
'Opens the file called Book1.xls.
xlObj.Workbooks.Open FileName:="c:\book1.xls"
'The variable strVar holds the contents of cell A1 on Sheet1 in
'the Book1.xls file.
strVar = xlObj.ActiveWorkbook.Sheets("Sheet1").Range("A1").Value
'Places the contents of strVar in the Task Name field of the
'first task in the open project file.
ActiveProject.Tasks(1).Name = strVar
End Sub
Sub Copy_From_Excel_To_Project()
'Sets the Object variable to contain Microsoft Excel Object.
Dim xlObj As Object
'Clears the xlObj object
Set xlObj = Nothing
'Sets the xlObj object as a Microsoft Excel Application object.
Set xlObj = CreateObject("Excel.Application")
'Opens the file Book1.xls.
xlObj.Workbooks.Open FileName:="c:\book1.xls"
'Selects cell A1 on Sheet1. Note that you can specify a range, such
'as .range("A1:D100").
xlObj.activeworkbook.Sheets("Sheet1").range("A1").Select
'Copies the contents of the selected cell to the Clipboard.
xlObj.Selection.Copy
'Selects the first row in Microsoft Project.
SelectBeginning
'Selects the name field for Task1.
SelectTaskField Row:=0, Column:="Name"
'Pastes the contents from the clipboard.
EditPaste
xlObj.CutCopyMode = False
End Sub
Additional query words: createobject create object vb vba
Keywords: kbbug kbdtacode kbpending KB163099