Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
best image on a userform | Excel Programming | |||
Refresh image on userform | Excel Programming | |||
Userform Image | Excel Programming | |||
Open image from web in window same size as image? | Excel Programming | |||
Userform Image help | Excel Programming |