Results 1 to 7 of 7

Thread: Executing Photoshop and opening images from within Excel

  1. #1

    Executing Photoshop and opening images from within Excel



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,165
    Articles
    57
    Blog Entries
    14
    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,
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Master your data with Power Query: Purchase your copy of my book M is for Data Monkey today!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  3. #3
    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
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Macro.JPG 
Views:	93 
Size:	42.4 KB 
ID:	156  

  4. #4
    Oops, yes it works perfectly!

    I had error in my path statement.

    Thanks very much - this will work very nicely!

  5. #5
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,165
    Articles
    57
    Blog Entries
    14
    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.
    Attached Files Attached Files
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Master your data with Power Query: Purchase your copy of my book M is for Data Monkey today!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  6. #6
    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!

  7. #7
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,165
    Articles
    57
    Blog Entries
    14
    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.)
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Master your data with Power Query: Purchase your copy of my book M is for Data Monkey today!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •