Results 1 to 2 of 2
  1. #1
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    82

    Copy OLE Object text to Word document

    Hello all

    I am using this to transfer one document into another via MS access (assume declarations).

    Code:
    Set SourceDoc = WrdApp.Documents.Open(strDocumentLocation, ReadOnly:=True, Visible:=False)
    WrdTbl.Cell(1, 1).Range.FormattedText = SourceDoc.Range.FormattedText
    However, I am finding it more efficient for the size of my documents to embed into an OLE field, and work with small documents there (for the project I am working on)

    But now, I am attempting to transfer the word text and formatting from an OLE object (word) back into a word document.



    e.g.

    WrdTbl.Cell(1, 1).Range.FormattedText = OLEObject.formattedText

    This wont work, so I'm wondered what the syntax is to make it work.

    I also tried:
    Code:
        Dim FrmMyForm As Form    Set FrmMyForm = Forms!Frm_MyOLEForm.Form
        With FrmMyForm.OLEControl
            WrdTbl.Cell(1, 1).Range = .Object.Content
        End With
    Also
    Code:
        RecSet!OLEField.Object.Content
    And
    Code:
        
         Set MyOLEObject = me.OLEControl      
         WrdTbl.Cell(1, 1).Range = MyOLEObject.Range.FormattedText
    This last one works to copy the content, but not formatted (despite the Range.FormattedText)

    I'm not finding help from google, so here I am.

    Any helpful advice or links appreciated.

  2. #2
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    82
    All.

    In the absence of an answer, I've written something that works - albeit in a convoluted way. Some of the code is changed for publishing but should anybody have a better solution, I would love to know about it.

    Code:
    Sub WriteOLEToWord()
    Dim WrdApp As Word.Application
    Dim WrdDoc As Word.Document
    Dim WrdDocProcedure As Word.Document
    Dim WrdTbl As Word.Table
    
    
    Dim strTemplateLocation As String
    Dim strSQL As String
    
    
    Dim FrmOLEProcedure As Form
    Dim MyOLEObject As BoundObjectFrame
    
    
        'Set string variables
        strSQL = "SELECT ProcedureEmbed FROM Tbl_Dat_Documents WHERE ID=1"
        strTemplateLocation = "C:\Temp Documents\Templates\SAMasterTemplate.dotx" ' Define the template Document
    
    
        Set WrdApp = CreateObject("Word.Application")
        WrdApp.Visible = True                 ' True for testing - Make false for live runtime
        WrdApp.ScreenUpdating = True    ' Prevents word displaying the update through entire procedure
        Set WrdDoc = WrdApp.Documents.Add(Template:=strTemplateLocation, NewTemplate:=False, DocumentType:=wdNewBlankDocument) ' Create the document from template
        Set WrdTbl = TableItem(WrdDoc, "Table: Procedure")                     ' Set the output location (Table) - TableItem function returns table from table name
    
    
        Set FrmOLEForm= Forms!Frm_MainForm.SubFrm_SubForm.Form   '  Set the OLE sub form
        Set MyOLEObject = FrmOLEForm.OLEProcedure                            '  Set the OLE Object
        With MyOLEObject
            .Verb = acOLEVerbOpen
            .Action = acOLEActivate                                                          ' Activate the OLE object into a word document - * Note:  there has to be a better way that this.
        End With
        Set WrdDocProcedure = WrdApp.ActiveDocument                          ' Set the newly active document
        WrdTbl.Cell(1, 1).Range.FormattedText = WrdDocProcedure.Range.FormattedText ' Copy the word document into the Table range
        WrdDocProcedure.Close                                                               ' Close the newly active document
    
    
        ' Display
        WrdApp.Visible = True ' Remember to make true end of procedure
        WrdApp.ScreenUpdating = True 
    
    
        ' Release
        Set WrdApp = Nothing '
        Set WrdDoc = Nothing '
        Set WrdTbl = Nothing '
        Set FrmOLEProcedure = Nothing
        Set MyOLEObject = Nothing
        Set WrdDocProcedure = Nothing
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Copy Data From One Word Document To Another
    By jo15765 in forum Programming
    Replies: 4
    Last Post: 05-09-2022, 09:51 AM
  2. Rename word document during copy/paste
    By Homegrownandy in forum Programming
    Replies: 3
    Last Post: 07-17-2018, 08:15 AM
  3. Replies: 4
    Last Post: 08-24-2015, 12:57 PM
  4. Move OLE Object from Access table to a Word Document
    By sneuberg in forum Programming
    Replies: 2
    Last Post: 07-18-2015, 11:55 AM
  5. Replies: 0
    Last Post: 06-14-2010, 07:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums