Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Picture BMP (Excel 2000)

    I scanned a 1 page document as a TIFF File. I used MS Imaging/ MS Paint to change it to bmp format. For some reason as soon as I want to load it as a picture onto a form it gives me an incorrect picture error. I've tried typing a few letters in MS Paint and saving it as a BMP and that works. Any thoughts on why it won't work.

    My other option is to scan it as a pdf file and then view it from the form. Will it be possible to write code for a button to start a PDF viewer and then view the scanned document?

    Thanks for the help all of you

  2. #2
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture BMP (Excel 2000)

    Hans will it be possible to have a hyperlink on a userform?

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Picture BMP (Excel 2000)

    Mario,

    No, I don't think there is an easy way to insert a hyperlink into a userform. The ShellExecute code is your best bet there, I'd say.
    (It's easy to insert a hyperlink in a cell in a spreadsheet, but that's not what you want, I think.)

    Regards,
    Hans

  4. #4
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture BMP (Excel 2000)

    Thanks for that news.

    I've tried you code but are uncertain where to put it all.

    The following I put in a std module:

    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

    Public Const SW_SHOWNORMAL = 1
    Public Const SW_SHOWMAXIMIZED As Long = 3

    Then I had the code for the button as follows:

    Private Sub CmdViewContract_Click()
    Dim lngResult As Long

    lngResult = ShellExecute(hWndAccessApp, "Open", _
    "<c:My Documents11879.xls", 0&, 0&, SW_SHOWNORMAL)
    'If lngResult <= 32 Then
    ' MsgBox "Can't open document.", vbExclamation
    'End If

    End Sub

    The program doesn't recognise the following: If lngResult <= 32 Then

    and I only have an initialise event. Should I put somewhere unload/load form to accommodate the code?

    Thanks

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture BMP (Excel 2000)

    You could place a label on the form, format it blue and underline and use its click event (like Hans showed for a commandbutton)
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  6. #6
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture BMP (Excel 2000)

    Can you maybe incorporating Hans's code on the attached workbook

    Thanks
    Attached Files Attached Files

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Picture BMP (Excel 2000)

    Mario,

    There was one mistake in my code - the reference to hWndAccessApp was there because I copied it from a post in the Access forum.
    I have attached a modified version of your workbook. You must substitute the correct path and filename of your picture file, otherwise you'll get a message that the document can't be opened.

    Regards,
    Hans
    Attached Files Attached Files

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Picture BMP (Excel 2000)

    <P ID="edit" class=small>(Edited by HansV on 29-Aug-02 13:10. )</P>A very simple way to open a document is to create a hyperlink to it.

    Another way is to use the WinAPI function ShellExecute. Put the following declarations in a standard module:

    <font color=blue>Please see later post in this thread for correction</font color=blue>

    <img src=/w3timages/blueline.gif width=33% height=2>
    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

    Public Const SW_SHOWNORMAL = 1
    Public Const SW_SHOWMAXIMIZED As Long = 3
    <img src=/w3timages/blueline.gif width=33% height=2>

    Use code like this in the OnClick event procedure of the command button:

    <img src=/w3timages/blueline.gif width=33% height=2>
    Dim lngResult As Long

    lngResult = ShellExecute(hWndAccessApp, "Open", _
    "<path-and-filename>", 0&, 0&, SW_SHOWNORMAL)
    If lngResult <= 32 Then
    MsgBox "Can't open document.", vbExclamation
    End If
    <img src=/w3timages/blueline.gif width=33% height=2>

    (replace <path-and-filename> by the full path and filename of your picture file)

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Picture BMP (Excel 2000)

    Here is a corrected version of the code - the code I posted previously was for Access.

    <img src=/w3timages/blueline.gif width=33% height=2>
    Declare Function FindWindow Lib "User32" Alias "FindWindowA" _
    (ByVal lpClassName As String, _
    ByVal lpWindowName As Long) As Long

    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

    Public Const SW_SHOWNORMAL = 1
    Public Const SW_SHOWMAXIMIZED As Long = 3
    <img src=/w3timages/blueline.gif width=33% height=2>

    Use code like this in the OnClick event procedure of a command button or label:

    <img src=/w3timages/blueline.gif width=33% height=2>
    Dim hWnd As Long
    Dim lngResult As Long
    hWnd = FindWindow("XLMAIN", 0)
    lngResult = ShellExecute(hWnd, "Open", _
    "<path-and-filename>", 0&, 0&, SW_SHOWNORMAL)
    If lngResult <= 32 Then
    MsgBox "Can't open document.", vbExclamation
    End If
    <img src=/w3timages/blueline.gif width=33% height=2>

    (replace <path-and-filename> by the full path and filename of the file you want to display)

  10. #10
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Picture BMP (Excel 2000)

    See this VBA thread for one or two more ideas, including using the Tag property of the control to store the url, thus allowing perhaps more discriptive text for display.

    Andrew C

  11. #11
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture BMP (Excel 2000)

    Thanks it works great. Is it possible to specify that it should use MS Imaging and not MS Paint. MS Paint is a bit scares on viewing properties.

  12. #12
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture BMP (Excel 2000)

    I am not sure what the advantage of using the WinApi is but am guessing that it is less machine dependent than the shell() command.
    but using shell() you can call imaging and pass the picture to it.

    Dim RetVal
    RetVal = Shell("C:Program FilesWindows NTAccessoriesImageVuekodakimg.exe C:tmp.bmp", 1)

    HTH

    Peter

  13. #13
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture BMP (Excel 2000)

    Peter where do I change the code to add your code.

    Thanks

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Picture BMP (Excel 2000)

    Mario,

    ShellExecute uses the associations you can set in Windows Explorer to decide what application is used to open a file. You might .bmp files to open with MS Imaging instead of MS Paint there. If you don't want to do that, you can use Bat17's suggestion to use Shell.

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Picture BMP (Excel 2000)

    Peter,

    The big advantage of the ShellExecute function is indeed that it is not machine-dependent. It uses the Windows Registry to decide what application to use. So it doesn't matter whether you decided to install a program on D: instead of on C:, or whether your system folder is Windows/Sytem or WinNT/System32 etc. And you don't see a DOS box.

    On the other hand, if you wish to open a file with a specific (non-standard) application, Shell is the easiest solution.

Page 1 of 2 12 LastLast

Posting Permissions

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