Embed Text File in Word Document RRS feed

  • Question

  • Hello all,

    I am trying to insert a text file as an object in the word document and it is not working. Pasting my code here.

    Dim oWord, oDoc
    Set oWord = CreateObject64("Word.Application")
    oWord.Visible = True
    Set oDoc = oWord.Documents.Add
    'First Try
    'oWord.Selection.InsertFile "C:\test123.txt", , , , True
    '2nd try
    'oWord.Selection.InlineShapes.AddOLEObject "C:\test123.txt"
    '3rd try
    'oWord.Selection.InlineShapes.AddOLEObject "C:\test123.txt", True

    Here First try is inserting the whole text from the text file but I need as attachment.

    2nd try - Giving me error saying "Program is used to create C:\test123. Either the required software not installed...."

    3rd try - Giving me error saying "Can't find the data for link -1"

    Now sure what i am doing wrong here. Anyone please throw some light here.

    • Moved by Bill_Stewart Monday, September 25, 2017 3:38 PM Move to more appropriate forum
    Monday, September 25, 2017 3:34 PM


  • Got the answer and I have passed invalid params.

    oWord.Selection.InlineShapes.AddOLEObject , "C:\test123.txt"

    First parameter is ClassType. Mention it or leave it as empty

    • Marked as answer by Shanmugavel C Monday, September 25, 2017 7:19 PM
    Monday, September 25, 2017 7:19 PM