PDA

View Full Version : Help needed for code to grab event when an object is dragged and dropped into Word



bert486
06-25-2014, 09:42 AM
Hello,

I'd like some help if anyone has worked on something similar.

Goal: I'm trying to code a macro that upon dragging and dropping another word file into an open word document will do the following:

1) Fire up an event
2) In this event grab information about that dropped file
3) Use information (file location, type) to open said file to grab certain textual information from within the file.

I've tried working with the office clip board, and this works if the file being dropped is text based such as an e-mail.msg from outlook. I was able to grab the subject from a dropped e-mail.msg file. However, if I drop an excel document or another word document an error is triggered related to the file format type not being supported.

What works so far for firing up the event:

I created a frame control that I placed in the word document. When I drag and drop an object onto this frame the following event fires up:

Dim Flag_1 As Boolean
Private Sub Frame1_BeforeDragOver(ByVal Cancel As MSForms.ReturnBoolean, ByVal Control As MSForms.Control, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal State As MSForms.fmDragState, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)

If Flag_1 = True Then
MsgBox "before drag"
Flag_1 = False
End If

End Sub

Private Sub Frame1_LostFocus()
Flag_1 = True
End Sub

-------------------------

Even though there's probably a better way to fire up the event, i can work with the frame drag event for now. The next step is to figure out how to grab information about the dropped file. I'm not sure where to go from here.

Any ideas are welcomed.

Thanks in advance!