PDA

View Full Version : Embed ms project in a table in ms word



hometech
09-24-2012, 11:05 PM
Hello, i currently embedded an ms project in my word document and it works fine but first, i want the embedded OLEobject to be loaded in a cell within a table in my word document and not just on the word document, any ideas please?
this is my code .


Sub Example()

Dim part As String
part = "C:\\NewProjectWork.mpp"

Set objx = ActiveDocument.Shapes.AddOLEObject(ClassType:="MSProject.Project", FileName:=part, LinkToFile:=True, DisplayAsIcon:=False, Anchor:=Selection.Range)

objx.Height = 400
objx.Width = 500
objx.Top = 100 'number of pixels from the top of the screen
objx.Left = 5 'number of pixels from the left of the screen

'Open object ready for typing
Set objx = Nothing
End Sub


Thanks

Excel Fox
09-25-2012, 01:03 AM
Try this....


Sub AddWordObject()

Dim objDoc As Document
Dim objTable As Table

Set objDoc = ActiveDocument
Set objTable = objDoc.Tables.Add(Range:=objDoc.Range, NumRows:=2, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed)
With objTable
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
.Cell(2, 1).Range.InlineShapes.AddOLEObject ClassType:="MSProject.Project", FileName:=part, LinkToFile:=True, DisplayAsIcon:=False, Range:=.Cell(2, 1).Range
End With

End Sub

hometech
09-25-2012, 02:38 PM
Thank you very much ExcelFox, it works like magic, but now the issue is that i want to be able to increase the height of the MS Project window and possibly merge the cells on that row so as to give the MS project window more area to display the gant chart.

using the code to increase the height of the MS Project window within the table so that i dont have to manually increase the height of the MS Project window.



Sub AddWordObject()

Dim objDoc As Document
Dim objTable As Table
Dim part As String
part = "C:\\NewProjectWork.mpp"

Set objDoc = ActiveDocument
Set objTable = objDoc.Tables.Add(Range:=objDoc.Range, NumRows:=2, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed)
With objTable
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
.Cell(2, 1).Range.InlineShapes.AddOLEObject ClassType:="MSProject.Project", FileName:=part, LinkToFile:=False, DisplayAsIcon:=False, Range:=.Cell(2, 1).Range
With InlineShapes.AddOLEObject
.Height = 100
.Width = 100
End With
End With

End Sub



i keep getting this error "server application, sourcefile or item cannot be found, make sure the application is properly installed........" and a runtime error 4198.

Also if i set the LiknToFile property of the object to true it treats the MS Project window like and image but if i set it to false, the window can be resized.

please what am I doing wrong and how do i go about it?
Thanks

Excel Fox
09-25-2012, 07:40 PM
Try this


Sub AddWordObject()

Dim objDoc As Document
Dim objTable As Table
Dim strPath As String
Dim objInlShp As InlineShape
Const lngRows As Long = 2
Const lngCols As Long = 3
Const lngRowToAddObject As Long = 2
Const lngColToAddObject As Long = 1
Const strClassType As String = "MSProject.Project"
strPath = "C:\\NewProjectWork.mpp"
Set objDoc = ActiveDocument
Set objTable = objDoc.Tables.Add(Range:=objDoc.Range, NumRows:=2, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed)
With objTable
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
.Range.Cells(lngCols * (lngRowToAddObject - 1) + 1).Row.Cells.Merge
Set objInlShp = .Cell(lngRowToAddObject, lngColToAddObject).Range.InlineShapes.AddOLEObject (ClassType:=strClassType, FileName:=strPath, LinkToFile:=False, DisplayAsIcon:=True, Range:=.Cell(lngRowToAddObject, lngColToAddObject).Range)
objInlShp.Width = .Cell(2, 1).Width
End With

End Sub



https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

hometech
09-26-2012, 02:59 PM
okay now thought i was through with this but it only seems that one problem leads to another.

Now after inserting the MS Project file into my table in MS Word, when i click on the project window to enter values and edit the project, i can view the task items and the gant chart fully, but when i click outside the MS Project window to return back to MS Word, the MS Project window automatically zooms and cuts away some part of the Gantt Chart which makes the ms Project window incomplete and cant see the end of the task.

Maybe the problem has to do with a window mode property, i have tried the various autoFit property and it does not seem to work.

any ideas please???

391

Excel Fox
09-26-2012, 10:16 PM
Did you try doing the whole thing manually, and then editing the MS Project file? Does it work fine in that case?

hometech
09-27-2012, 12:57 PM
yes i already tried it but it is pretty much does the same thing. The thing is that when the MS Project window is active, it behaves fine but when i switch back to MS Word, it then zooms and cuts part of the gantt chart. i attached the file.
Thanks