Results 1 to 7 of 7

Thread: Embed ms project in a table in ms word

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Embed ms project in a table in ms word

    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 .
    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

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Try this....

    Code:
    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
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0
    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.

    Code:
    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

  4. #4
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Try this

    Code:
    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
    Last edited by DocAElstein; 06-12-2023 at 01:03 PM.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  5. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0
    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???

    msProj.JPG

  6. #6
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Did you try doing the whole thing manually, and then editing the MS Project file? Does it work fine in that case?
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  7. #7
    Junior Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0
    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
    Attached Files Attached Files

Similar Threads

  1. Replies: 7
    Last Post: 08-24-2015, 10:58 PM
  2. Excluding Records of one Table from the Other Table
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 05-17-2013, 12:32 AM
  3. Replies: 1
    Last Post: 10-16-2012, 01:53 PM
  4. Saving Embedded Picture From Excel Workbook Sheet To Folder Hard Drive
    By littleiitin in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 10-31-2011, 02:31 PM
  5. Project Planner
    By littleiitin in forum Download Center
    Replies: 0
    Last Post: 09-03-2011, 07:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •