PDA

View Full Version : [SOLVED:] drag and drop?



Kilroy
12-14-2016, 08:27 AM
Guys I have 2 questions:

1. I'm wondering if it's possible for a macro to open a file picking window where you could pick a file or drag and drop a file into it and then when you do it executes a given macro.

2. If question #1 is possible, if that file is PDF can it be set to automatically open it in word?

Any advice is appreciated.

Kilroy
12-16-2016, 07:35 AM
I've come up with some code but it's not quite working properly. When the document opens it is not becoming the active document so the "RunAll" macro runs on a different document than the one I opened. I tried adding a line to switch it to active but can't get it right. How do I name it? Any suggestions?


Sub PickAndRun()
Dim intChoice As Integer
Dim strPath As String
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
intChoice = Application.FileDialog(msoFileDialogOpen).Show
'if the user selects a file
If intChoice <> 0 Then
'get the path selected
strPath = Application.FileDialog( _
msoFileDialogOpen).SelectedItems(1)
'opens the document
objWord.Documents.Open (strPath)
End If
Set ???????? = ActiveDocument
Application.Run MacroName:="RunAll"

Kilroy
12-16-2016, 09:50 AM
It seems to be skipping everything past

intChoice = Application.FileDialog(msoFileDialogOpen).Show

and going right to

Application.Run MacroName:="RunAll"
I tried putting in a count command but it doesn't get to it


Sub PickAndRun()
Dim intChoice As Integer
Dim strPath As String
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
intChoice = Application.FileDialog(msoFileDialogOpen).Show
'if the user selects a file
If intChoice <> 0 Then
'get the path selected
strPath = Application.FileDialog( _
msoFileDialogOpen).SelectedItems(1)

'opens the document
objWord.Documents.Open (strPath)
objWord.Activate
End If
'Set ???????? = ActiveDocument Documents.Open(origDoc).Activate
For iCount = 1 To 5000
Next iCount
Application.Run MacroName:="RunAll"
End Sub


When I run it without the Application.Run MacroName:="RunAll" it opens and becomes the active document but still skips everything after the intChoice = line. I'm stumped

Kilroy
12-16-2016, 02:13 PM
Got it sorted out!


Dim doc As Document
Set doc = Documents.Open(strPath)
With doc
Application.Run MacroName:="MyOtherMacros"

End With

gmaxey
12-16-2016, 05:04 PM
I don't see what purpose With doc and End With doc serves in your last post.

Kilroy
12-16-2016, 08:16 PM
I thought it was needed to ensure the "Application.Run MacroName:="MyOtherMacros"" applied to the newly opened document. I'm still a newbie. Thanks for your input I'll try taking it out. Thanks Greg