+ Reply to Thread
Results 1 to 12 of 12

How to open .jpg picture with macro

  1. #1
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    How to open .jpg picture with macro

    I use the following macro to open excel files. Can this be modified to open
    a picture ppppp.jpg ?

    . . . or, can someone help me with a new macro that can open pictures
    . . . I would still like to have the file checking options to see if the picture is already open and if not, that it actually exists.


    Please see bottom of this posting for additional question!

    Thanks
    Matt @ Launchnet


    Please Login or Register  to view this content.
    P.S. - - - I am still looking for a way to activate the workbook we're looking for when the above test states that it is already open.
    Last edited by Launchnet; 02-24-2009 at 02:02 AM.
    Thanks for helping . . .
    Matt @ Launchnet

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: How to open .jpg picture with macro

    Hello Matt,

    The following macro will open a picture using the default program for the picture type. Change the the variable PicPath to the picture file you want to display. Copy this code into a standard VBA module.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to open .jpg picture with macro

    Hi Leith - Good hearing from you

    First, I copied the code to my VBA module.
    Then I typed in the correct path to the picture.
    When I stepped into the code, I got the following error message.

    Compile error:
    Only comments may appear after End Sub, End Function or End Property.

    There is a macro prior to your Private Declare Function ShellExecute _

    Maybe I should be putting something like Sub at the beginning and End Sub at the end, but I don't know what it should be.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: How to open .jpg picture with macro

    The stuff that starts with Private Declare has to be at the top of the module, with nothing above it other than compiler directives (e.g., Option Explicit). The Sub can go anyplace in the module.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to open .jpg picture with macro

    Moved the Private Declare stuff to the very top.

    No error msg.

    I stepped thru and when RetValu = . . . is high-lited, I hovered over the PicPath and it does not have a value ???

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: How to open .jpg picture with macro

    Change the right side of the assignment to point to a valid path and filename on your computer, Matt.

  7. #7
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to open .jpg picture with macro

    Shg - Thanks . . . I forgot an "s" at the end of a folder. Works perfect. I will mark as Solved.

    I really enjoy working with you guys. I've learned alot, but I've still got a long ways to go. Well, I still have lots of years left as I'm only 77.

    Thanks again

  8. #8
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to open .jpg picture with macro

    Good Morning SHG

    Your code works, but I would like to better understand the code.

    Could you explain to me how this line of code works or the meanings of code please:

    Please Login or Register  to view this content.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: How to open .jpg picture with macro

    Hello Matt,

    I will keep it simple because this is a low level system call. Explaining how all the arguments function and where they come from is too much detail to explain in this post.

    The ShellExecute code is an API (Applications Programming Interface) call. The procedure will open the executable program associated with the file's extension. This call uses uses the verb "open" to run the executable program for the file's type. The file, including the path and the file extension, is the third parameter. The last parameter determines the window state when the program is run. Normal size is chosen.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: How to open .jpg picture with macro

    Good Morning SHG

    Your code works ...
    Leith's code, Matt

  11. #11
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to open .jpg picture with macro

    Good Morning Leith

    Please Login or Register  to view this content.
    I understand RetVal = ShellExecute( ?, "open, PicPath, ?, ?, ?)

    Is their an easy explaination of the areas with question marks ? In general, what they mean.

    If not, forget it, as I understand where you are coming from.

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: How to open .jpg picture with macro

    Hello Matt,

    Click on this link to see a full explanation of the call.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1