Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default open an image from a userform

I have a user form with a command button, that when clicked I would like to
open a picture in the users default picture viewer. Any help on how to
accomplish this would be greatly appreciated.

Would it be better to just creat another userform with the image on it and
then just show the form when the button is clicked?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default open an image from a userform

Copy/Paste this code line into a Module (click Insert/Module from the VB
editor's menu bar)...

Public 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 can then show a picture by specifying its full path to the ShellExecute
function as shown in this example macro...

Sub ShowPicture()
Dim FileName As String
FileName = "D:\Programming\VB Code\3.bmp"
ShellExecute Application.hwnd, "Open", FileName, "", "", vbNormalFocus
End Sub

Just change my example full path/filename assigned to the FileName variable
to the full path/filename for your picture file. Of course, you can query
the user for the filename and path if that is what you are ultimately
wanting to do.

As for your "Would it be better to just create another userform with the
image on it and then just show the form when the button is clicked?"
question... that depends on how you want the code to work... it is your
choice. One thing that may be a consideration for you is that the default
viewer can display many more picture file formats than can be done using a
UserForm's (or Image control's) Picture property.

--
Rick (MVP - Excel)


"Brad" wrote in message
...
I have a user form with a command button, that when clicked I would like to
open a picture in the users default picture viewer. Any help on how to
accomplish this would be greatly appreciated.

Would it be better to just creat another userform with the image on it and
then just show the form when the button is clicked?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default open an image from a userform

Where is the picture located? In the worksheet or on a drive?

"Brad" wrote:

I have a user form with a command button, that when clicked I would like to
open a picture in the users default picture viewer. Any help on how to
accomplish this would be greatly appreciated.

Would it be better to just creat another userform with the image on it and
then just show the form when the button is clicked?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default open an image from a userform

Rick,

Thanks for the snippet below, it works great for an application I am
writing. Do you have any idea how to do a similar thing to open an MPEG file
in the users default movie player?

"Rick Rothstein" wrote:

Copy/Paste this code line into a Module (click Insert/Module from the VB
editor's menu bar)...

Public 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 can then show a picture by specifying its full path to the ShellExecute
function as shown in this example macro...

Sub ShowPicture()
Dim FileName As String
FileName = "D:\Programming\VB Code\3.bmp"
ShellExecute Application.hwnd, "Open", FileName, "", "", vbNormalFocus
End Sub

Just change my example full path/filename assigned to the FileName variable
to the full path/filename for your picture file. Of course, you can query
the user for the filename and path if that is what you are ultimately
wanting to do.

As for your "Would it be better to just create another userform with the
image on it and then just show the form when the button is clicked?"
question... that depends on how you want the code to work... it is your
choice. One thing that may be a consideration for you is that the default
viewer can display many more picture file formats than can be done using a
UserForm's (or Image control's) Picture property.

--
Rick (MVP - Excel)


"Brad" wrote in message
...
I have a user form with a command button, that when clicked I would like to
open a picture in the users default picture viewer. Any help on how to
accomplish this would be greatly appreciated.

Would it be better to just creat another userform with the image on it and
then just show the form when the button is clicked?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default open an image from a userform

Rick,

Never mind, I figured it out. Your code works based on the file extension.
Just had to get the right one. Thanks again.

"quaz" wrote:

Rick,

Thanks for the snippet below, it works great for an application I am
writing. Do you have any idea how to do a similar thing to open an MPEG file
in the users default movie player?

"Rick Rothstein" wrote:

Copy/Paste this code line into a Module (click Insert/Module from the VB
editor's menu bar)...

Public 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 can then show a picture by specifying its full path to the ShellExecute
function as shown in this example macro...

Sub ShowPicture()
Dim FileName As String
FileName = "D:\Programming\VB Code\3.bmp"
ShellExecute Application.hwnd, "Open", FileName, "", "", vbNormalFocus
End Sub

Just change my example full path/filename assigned to the FileName variable
to the full path/filename for your picture file. Of course, you can query
the user for the filename and path if that is what you are ultimately
wanting to do.

As for your "Would it be better to just create another userform with the
image on it and then just show the form when the button is clicked?"
question... that depends on how you want the code to work... it is your
choice. One thing that may be a consideration for you is that the default
viewer can display many more picture file formats than can be done using a
UserForm's (or Image control's) Picture property.

--
Rick (MVP - Excel)


"Brad" wrote in message
...
I have a user form with a command button, that when clicked I would like to
open a picture in the users default picture viewer. Any help on how to
accomplish this would be greatly appreciated.

Would it be better to just creat another userform with the image on it and
then just show the form when the button is clicked?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
best image on a userform obsessive Excel Programming 0 May 4th 06 10:25 PM
Refresh image on userform Graham S Excel Programming 2 March 22nd 06 09:45 PM
Userform Image Jennifer Excel Programming 10 February 24th 06 07:44 PM
Open image from web in window same size as image? Milos Setek Excel Programming 0 February 5th 04 03:33 AM
Userform Image help Pete[_13_] Excel Programming 1 November 10th 03 10:26 PM


All times are GMT +1. The time now is 03:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"