Executing Photoshop and opening images from within Excel

Joeclarke

New member
Joined
Jul 14, 2011
Messages
4
Reaction score
0
Points
0
I'm trying to use Excel as a catalogue for accessing a large dynamic listing of images and videos. These items would be opened using CS5 for editing purposes or other programs (virtual drives, etc.) for viewing.

Excel works particularly well for catalogue purposes and makes for a great look-up-table that's easily updated and manipulated by a number of users.

I'd like to complete the catalogue to execution gap by adding some macro buttons to the spreadsheet items that would cause the appropriate executable to initiate and the appropriate file to be opened.

I tried this approach to get started based on something that came out of a google search:

Shell ("d:\program files\adobe\adobe photoshop CS5(64bit)\photoshop.exe")

Although the path is correct - this initiates runtime error no. 63 file not found.

I'm using Excel 2003 and Windows 7 (64).

Thanks for any suggestions
 
Hi there, and welcome to the board!

I use a Windows API call to do this. This code goes at the top of your module, after any option lines and global variables, but before any subroutines or functions:

Code:
    Private Declare Function ShellExecute _
                          Lib "shell32.dll" _
                              Alias "ShellExecuteA" ( _
                              ByVal hwnd As Long, _
                              ByVal lpOperation As String, _
                              ByVal lpFile As String, _
                              ByVal lpParameters As String, _
                              ByVal lpDirectory As String, _
                              ByVal nShowCmd As Long) _
                              As Long

You'd then call this as follows:
Code:
ShellExecute 0, "Open", sFileName, "", "", 1

In this case, sFilename is the path, name and extension of your file. You don't need to tell it which application it is, as the ShellExecute API uses windows file association to figure that out for you.

HTH,
 
Thanks very much for pointing me in a new direction.

To get my "feet wet" I copied your code and tried this to open a simple jpg sitting on the desktop.

When I try call this macro nothing happens. No error message.

But I'll keep playing around with this concept until I sort it out.

Thanks again
 

Attachments

  • Macro.JPG
    Macro.JPG
    42.4 KB · Views: 124
Oops, yes it works perfectly!

I had error in my path statement.

Thanks very much - this will work very nicely!
 
Cool, glad you got it sorted. I saw the email notification of your reply, so pulled this together to demo it. Obviously not needed now, but figured I'd upload it anyway, as maybe it will help someone else in future. :)
 

Attachments

  • xlgf274-1.xls
    38 KB · Views: 263
Excellent demo Ken, I've saved it in my "toolbox" for future reference.

I've started adding macro buttons to open image files from within the catalogue using this format.

Works brilliantly!

Can you think of a coding workaround for iso image video files that need to be mounted to a virtual drive in order to opened by a program?

Let's say I have a virtual drive "X" and an iso image, say "video.iso". In order to view the iso the normal process is to right click on the image file and select the option "Mount to X". Once mounted to the drive the image file may be executed. So it's a 2-stage process to view an iso. Mount it, then execute it using the default player.

Unmounted it is not accessible. It's the virtual equivalent of physically inserting a dvd into a drive bay.

This may be a question for the virtual drive forum, I will also post it there to see if there are ideas to code around this in VBA.

Thanks again for your help!
 
Off the top of my head, no I can't, but I'm absolutely certain that this could be done with the right Windows API calls. The question is which ones...

You may want to search for VB code to do it (rather than VBA). Once you find that, I'll bet we could probably modify it to be called from VBA. (Maybe not me, but I know a couple of guys who would be capable.)
 
Back
Top