PC Review


Reply
Thread Tools Rate Thread

Displaying jpegs.

 
 
videor
Guest
Posts: n/a
 
      27th Mar 2007
I am running Office 2000 in WinXP.

I have a need to display several dozen .jpg files, each 10 megs or so in
size in a workbook, with 4 or 5 of them accessable from each worksheet.
Placing each entire picture into the workbook, it becomes unwieldy in size.
I have decided to place buttons on each worsheet with thumbnails of the
picture to be displayed on the button, so that when the button is pressed,
the full size file is displayed.

The following VBA code works:

Dim RetVal
RetVal = Shell("rundll32.exe
C:\WINDOWS\system32\shimgvw.dll,ImageView_Fullscreen
picture_name_and_path.jpg", 1)

This displays the full size picture in Windows picture and fax viewer. It is
a solution I can live with. But what I really want to do is to display the
picture using whatever the default .jpg viewer is for that computer just as
if the picture file was double clicked.

There must be some function such as "show using default pic.jpg"

If this is not clear, I can further explain.

Thanks




 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      27th Mar 2007
You have a few choices.
..FollowHyperlink will open it in IE.
The ShellExecute API will open in the app associated with that file type.

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
Const SW_SHOWNORMAL = 1

Private Sub CommandButton3_Click()
Dim RetVal As Long

Const FileName As String = "C:\Sample.jpg"

ThisWorkbook.FollowHyperlink FileName
'or
RetVal = ShellExecute(Application.hwnd, "open", FileName, vbNullString,
"C:\", SW_SHOWNORMAL)

End Sub

Or you could keep it all inside Excel, by using an Image control (on the WS
or modeless userform) and load the picture into that.
That way it is not saved with the WB.

NickHK

"videor" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am running Office 2000 in WinXP.
>
> I have a need to display several dozen .jpg files, each 10 megs or so in
> size in a workbook, with 4 or 5 of them accessable from each worksheet.
> Placing each entire picture into the workbook, it becomes unwieldy in

size.
> I have decided to place buttons on each worsheet with thumbnails of the
> picture to be displayed on the button, so that when the button is pressed,
> the full size file is displayed.
>
> The following VBA code works:
>
> Dim RetVal
> RetVal = Shell("rundll32.exe
> C:\WINDOWS\system32\shimgvw.dll,ImageView_Fullscreen
> picture_name_and_path.jpg", 1)
>
> This displays the full size picture in Windows picture and fax viewer. It

is
> a solution I can live with. But what I really want to do is to display the
> picture using whatever the default .jpg viewer is for that computer just

as
> if the picture file was double clicked.
>
> There must be some function such as "show using default pic.jpg"
>
> If this is not clear, I can further explain.
>
> Thanks
>
>
>
>



 
Reply With Quote
 
videor
Guest
Posts: n/a
 
      28th Mar 2007
Thanks for the additional ideas. I got the IE version to work, and the Image
control. However, I can't get the ShellExecute to work. The statement
"retval=shellexecute(..." crashes with a "object doesn't support this
property or method" message. the entire statement is highlighted.

bern muller


"NickHK" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You have a few choices.
> .FollowHyperlink will open it in IE.
> The ShellExecute API will open in the app associated with that file type.
>
> 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
> Const SW_SHOWNORMAL = 1
>
> Private Sub CommandButton3_Click()
> Dim RetVal As Long
>
> Const FileName As String = "C:\Sample.jpg"
>
> ThisWorkbook.FollowHyperlink FileName
> 'or
> RetVal = ShellExecute(Application.hwnd, "open", FileName, vbNullString,
> "C:\", SW_SHOWNORMAL)
>
> End Sub
>
> Or you could keep it all inside Excel, by using an Image control (on the
> WS
> or modeless userform) and load the picture into that.
> That way it is not saved with the WB.
>



 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      29th Mar 2007

This is part of the Windows API. Excel/VBA know nothing about it, so you
have include the declarations that I included, in the top section of the
code module:

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
Const SW_SHOWNORMAL = 1

NickHK


"videor" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for the additional ideas. I got the IE version to work, and the

Image
> control. However, I can't get the ShellExecute to work. The statement
> "retval=shellexecute(..." crashes with a "object doesn't support this
> property or method" message. the entire statement is highlighted.
>
> bern muller
>
>
> "NickHK" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > You have a few choices.
> > .FollowHyperlink will open it in IE.
> > The ShellExecute API will open in the app associated with that file

type.
> >
> > 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
> > Const SW_SHOWNORMAL = 1
> >
> > Private Sub CommandButton3_Click()
> > Dim RetVal As Long
> >
> > Const FileName As String = "C:\Sample.jpg"
> >
> > ThisWorkbook.FollowHyperlink FileName
> > 'or
> > RetVal = ShellExecute(Application.hwnd, "open", FileName, vbNullString,
> > "C:\", SW_SHOWNORMAL)
> >
> > End Sub
> >
> > Or you could keep it all inside Excel, by using an Image control (on the
> > WS
> > or modeless userform) and load the picture into that.
> > That way it is not saved with the WB.
> >

>
>



 
Reply With Quote
 
videor
Guest
Posts: n/a
 
      29th Mar 2007
I had done that. But based on your assurance that was what should be done, I
did a little troubleshooting and found the problem:

The call as you sent it was: (without quotes)

"RetVal = ShellExecute(Application.hwnd, "open", FileName, vbNullString,
"C:\", SW_SHOWNORMAL)"

I changed it to:

"RetVal = ShellExecute(hwnd, "open", FileName, vbNullString,
"C:\", SW_SHOWNORMAL)"

and that seems to work. Any reason not to do it that way?

Thanks for all the help.

bern

"NickHK" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> This is part of the Windows API. Excel/VBA know nothing about it, so you
> have include the declarations that I included, in the top section of the
> code module:
>
> 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
> Const SW_SHOWNORMAL = 1
>
> NickHK



 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      30th Mar 2007
What is your value of hwnd ?

This should be the Windows handle of the parents window, hence
Application.hwnd.
This only works in Excel 2002 and higher.
In earlier versions, you should use the FindWindow API.

NickHK

"videor" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I had done that. But based on your assurance that was what should be done,

I
> did a little troubleshooting and found the problem:
>
> The call as you sent it was: (without quotes)
>
> "RetVal = ShellExecute(Application.hwnd, "open", FileName, vbNullString,
> "C:\", SW_SHOWNORMAL)"
>
> I changed it to:
>
> "RetVal = ShellExecute(hwnd, "open", FileName, vbNullString,
> "C:\", SW_SHOWNORMAL)"
>
> and that seems to work. Any reason not to do it that way?
>
> Thanks for all the help.
>
> bern
>
> "NickHK" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > This is part of the Windows API. Excel/VBA know nothing about it, so you
> > have include the declarations that I included, in the top section of the
> > code module:
> >
> > 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
> > Const SW_SHOWNORMAL = 1
> >
> > NickHK

>
>



 
Reply With Quote
 
videor
Guest
Posts: n/a
 
      30th Mar 2007
I am using Excel 2000. Works well for me, and I am too stingy to upgrade.
:-)

The value of hwnd was null. But it worked anyway. In an effort to do it
right, I implemented the following code:

Declarations:

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
Const SW_SHOWNORMAL = 1

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
*********************************************************
On worksheet:

Private Sub CommandButton1_Click()
Dim RetVal As Long
Dim hwind As Long

hwnd = FindWindow(vbNullString, Application.Caption)

RetVal = ShellExecute(hwnd, "open", ThisWorkbook.Path & "\PICT7550.JPe",
vbNullString, "C:\", SW_SHOWNORMAL)

End Sub

That works and delivers some humungous number for hwind. I imagine the extra
code will make it more machine independent. Interesting that it works even
when hwnd is a null. I tried plugging in several arbitrary numbers and they
all worked. Maybe some other display programs will be more fussy.

Thanks yet again for the help and suggestions.


"NickHK" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> What is your value of hwnd ?
>
> This should be the Windows handle of the parents window, hence
> Application.hwnd.
> This only works in Excel 2002 and higher.
> In earlier versions, you should use the FindWindow API.
>
> NickHK
>



 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      30th Mar 2007
Getting the hwnd will yield a Long value for the main Excel window, XLMAIN.
The hwnd is used if some message box needs to be shown or notification sent
to a window.
If the value is not valid, outcome would be unpredictable.
<guess>
As long as that is not the case, the hwnd is probably ignored.
</guess>

For the sake of an extra declaration and one line of code, it worth doing
correctly.

NickHK

"videor" <(E-Mail Removed)> wrote in message
news:8ZydnTkzq8-(E-Mail Removed)...
> I am using Excel 2000. Works well for me, and I am too stingy to upgrade.
> :-)
>
> The value of hwnd was null. But it worked anyway. In an effort to do it
> right, I implemented the following code:
>
> Declarations:
>
> 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
> Const SW_SHOWNORMAL = 1
>
> Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
> lpClassName As String, ByVal lpWindowName As String) As Long
> *********************************************************
> On worksheet:
>
> Private Sub CommandButton1_Click()
> Dim RetVal As Long
> Dim hwind As Long
>
> hwnd = FindWindow(vbNullString, Application.Caption)
>
> RetVal = ShellExecute(hwnd, "open", ThisWorkbook.Path & "\PICT7550.JPe",
> vbNullString, "C:\", SW_SHOWNORMAL)
>
> End Sub
>
> That works and delivers some humungous number for hwind. I imagine the

extra
> code will make it more machine independent. Interesting that it works even
> when hwnd is a null. I tried plugging in several arbitrary numbers and

they
> all worked. Maybe some other display programs will be more fussy.
>
> Thanks yet again for the help and suggestions.
>
>
> "NickHK" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > What is your value of hwnd ?
> >
> > This should be the Windows handle of the parents window, hence
> > Application.hwnd.
> > This only works in Excel 2002 and higher.
> > In earlier versions, you should use the FindWindow API.
> >
> > NickHK
> >

>
>



 
Reply With Quote
 
videor
Guest
Posts: n/a
 
      31st Mar 2007
I am using Excel 2000. Works well for me, and I am too stingy to upgrade.
:-)

The value of hwnd was null. But it worked anyway. In an effort to do it
right, I implemented the following code:

Declarations:

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
Const SW_SHOWNORMAL = 1

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
*********************************************************
On worksheet:

Private Sub CommandButton1_Click()
Dim RetVal As Long
Dim hwind As Long

hwnd = FindWindow(vbNullString, Application.Caption)

RetVal = ShellExecute(hwnd, "open", ThisWorkbook.Path & "\PICT7550.JPe",
vbNullString, "C:\", SW_SHOWNORMAL)

End Sub

That works and delivers some humungous number for hwind. I imagine the extra
code will make it more machine independent. Interesting that it works even
when hwnd is a null. I tried plugging in several arbitrary numbers and they
all worked. Maybe some other display programs will be more fussy.

Thanks yet again for the help and suggestions.


"NickHK" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> What is your value of hwnd ?
>
> This should be the Windows handle of the parents window, hence
> Application.hwnd.
> This only works in Excel 2002 and higher.
> In earlier versions, you should use the FindWindow API.
>
> NickHK



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying Jpegs on form. RJamis Microsoft Access Database Table Design 2 7th Mar 2009 03:29 PM
Displaying jpegs from SQL Server in a report CR Developer Microsoft Dot NET 0 26th Oct 2006 09:13 PM
playing mpeg4 or displaying jpegs using C# curtis.barrett@gmail.com Microsoft C# .NET 3 28th Dec 2005 05:01 PM
Displaying JPEGs in an Image Control Dave Monks Microsoft Access 8 20th Sep 2005 11:39 AM
Displaying Jpegs on a web page!? =?Utf-8?B?V2ViIFNsaW5nZXI=?= Windows XP Networking 2 23rd Feb 2005 11:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:27 AM.