Jay
Jay

Reputation: 123

Would like to run an Excel macro with drag and drop

I have a macro that asks the user to choose an excel file and then outputs two text files based on the data.

I am looking for a way to just drop the excel file onto the macro file and have it process without the need for opening the macro file, a command button, an open file dialog, etc. I would like to drop the file on the other file and just have the two text files output.

I saw something that looked promising using a VBS file, but was unable to get it to work.

Upvotes: 2

Views: 3974

Answers (1)

Marc
Marc

Reputation: 11613

Here's the bare bones of what you need to do:

Wscript.echo "Begin..."           'just letting you know it's working
Set objArgs = Wscript.Arguments   'capture arguments; arg 0 is the name of the dropped file
Wscript.echo "The file name you dropped is:" & objArgs(0)

'DO STUFF TO THE FILE HERE

Wscript.echo "...Finished"        'all done
  1. Save this to a file with a "vbs" extension.
  2. Drag and drop a file onto it.
  3. If your Windows file associations are properly setup, you'll see this output a message for each of the wscript.echo lines.

Upvotes: 1

Related Questions