PDA

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



hometech
09-24-2012, 10:57 AM
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

fumei
09-24-2012, 01:49 PM
You are using:Anchor:=Selection.Rangeas the anchor. That is, the Shape is anchored to the Selection.

Make it anchored to the cell range.

Anchor:=ActiveDocument.Tables(2).Cell(3,1).RangeAnchored to cell (row3, column 1) of the second table.

However, there is a bit of a problem. You are making explicitl co-ordinates to the screen. Not a cell.

So there may be dimension issues. I would imagine there would be. So you would have to:

1. change your numbers
2. change the cell dimensions to fit

Or both. If you change the the size of the Shape, and you have AutoFit, it may work. I am not sure if the Top and Left will work in a cell the way you want, but you could probably may it work defining a Style for the cell range that encompasses what you want. In other words, make a style with space before and after set for what you want, apply the style to the cell you want, and THEN insert the Shape.

It will get anchored to the paragraph of the cell (as all cells have at least one paragraph.

I am not sure this will work, but in theory it may. Try it and get back to us.

hometech
09-25-2012, 05:55 AM
Thank you very much fumei, you suggestion worked very fine
Anchor:=ActiveDocument.Tables(2).Cell(3,1).Range

for the cell to be able to properly contain the default height of the MS Project window, i added the inline to the shape property of add OLEObject

Set objx = ActiveDocument.InlineShapes.AddOLEObject(ClassType:="MSProject.Project", _
FileName:=part, LinkToFile:=False, DisplayAsIcon:=False, Range:=ActiveDocument.Tables(1).Cell(24, 1).Range)

the object width works fine but the height doesnt increase as desired, maybe it works as a ratio to the object width.

Thanks very much, i really appreciate your help.:thumb:clap:

fumei
09-25-2012, 10:42 PM
You are welcome.

hometech
09-26-2012, 03:03 AM
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???

fumei
09-26-2012, 03:09 PM
I do not have Project so I can not do any testing. I suspect that it is a Project issue - although of course I can not sure. But if it is Project not showing things correctly, that sounds like a Project issue.

So I am sorry to say, I have no ideas.

hometech
09-27-2012, 10:20 AM
anyway, thanks all the same