Share via

Drop-Zone behavior in Word VB-Script

Anonymous
2023-03-10T10:36:13+00:00

Hi VB Gurus,

I'm trying to migrate old versions of reports to new report format. The details are written in table cells inside word doc.
So basically I should copy cell content from the source-document to the destination-document, but structure is a bit different:

SOURCE

DESTINATION

I created a destination-template with a drop-zone (rectangle), so the idea is, that I pull the old report as source document from the
File Explorer, drag it on the drop-zone and the VB reads the source cells and writes the read content in the destination cells. The idea would be to open the source document in the background, parse it, store the cell context into a matrix and close it. Later the matrix fields will be written to the destination cells.

Unfortunately if I dropepd a file inside the Word document, Word handles as include, so the full document content will be attached to the destination document as an object, and the event handler not called.

Any idea how to configure Word to call the event handler (and maybe don't include anything)?

The current subrutine header is the following:

Private Sub dropZone1_DragDrop (ByVal Data As MSForms.DataObject, ByVal Effect As Long, ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

Thanks,

Peter

Microsoft 365 and Office | Word | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2023-03-11T02:23:59+00:00

    I believe that you will need to use something like

    Dim DocSource As Document, DocTarget As Document

    Dim TableTemp As Table

    Dim rngTemp As Range

    Set DcoSource = ActiveDocument

    Set DocTarget = Documents.Add("New Form Template")

    Set TableTemp = DocSource.Tables(1)

    Set rngTemp = TableTemp.ConvertToText(Separator:=wdSeparateByParagraphs)

    With DocTarget.Tables(1)

    .Cell(1, 2).Range = rngTemp.Paragraphs(2).Range 
    
    .Cell(1, 4).Range = rngTemp.Paragraphs(4).Range 
    
    .Cell(2, 2).Range = rngTemp.Paragraphs(8).Range 
    
    .Cell(3, 2).Range = rngTemp.Paragraphs(10).Range 
    
    .Cell(4, 2).Range = rngTemp.Paragraphs(14).Range 
    
    .Cell(5, 2).Range = rngTemp.Paragraphs(16).Range 
    
    .Cell(6, 2).Range = rngTemp.Paragraphs(6).Range 
    
    .Cell(7, 2).Range -rngTemp.Paragraphs(12).Range 
    

    End With

    Was this answer helpful?

    0 comments No comments