Save picture in IrfanView from Excel macro

jolivanes
Lounger
Posts: 28
Joined: 24 Nov 2015, 05:23

Save picture in IrfanView from Excel macro

Post by jolivanes »

If I remember right, I copied this from a solution by snb. Not 100% sure though.
I would like to add a possibility to save the picture to a folder, hard coded in code.

Code: Select all

Private Sub Cmd31_Click()
Dim cv As String, Viewer As String
Select Case Environ("computername")
Case Is = "DESKTOP"
cv = "C:\Program Files\IrfanView\i_view64.exe"
Case Is = "LAPTOP"
cv = "C:\Program Files (x86)\IrfanView\i_view32.exe"
End Select
Viewer = cv
     Selection.Copy
     Shell Viewer, 1
     Application.SendKeys "^v"
     SendKeys "{NUMLOCK}", True
     Unload Me
End Sub
I found this but would not know how to implement that in the code.

Code: Select all

 /convert=filename -
Does someone know how to?

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save picture in IrfanView from Excel macro

Post by HansV »

This is untested:

Code: Select all

Private Sub Cmd31_Click()
    Dim cv As String
    Dim path As String
    Select Case Environ("computername")
        Case "DESKTOP"
            cv = "C:\Program Files\IrfanView\i_view64.exe"
        Case "LAPTOP"
            cv = "C:\Program Files (x86)\IrfanView\i_view32.exe"
    End Select
    path = "C:\Test\Output.png"
    Selection.Copy
    Shell cv & " ""/clippaste /convert=" & path & """", vbNormalFocus
    Unload Me
End Sub
Best wishes,
Hans

snb
4StarLounger
Posts: 585
Joined: 14 Nov 2012, 16:06

Re: Save picture in IrfanView from Excel macro

Post by snb »

No I don't remember having made this code.
You might simplify:

Code: Select all

Private Sub Cmd31_Click()
  c00 = mid(Environ(18),14) & "\Irfanview\"
  shell  c00 & dir(c00 & "i_view*.exe") & " /clippaste /convert=G:\OF\pict.png", 0
end sub
Tested & delivering.

jolivanes
Lounger
Posts: 28
Joined: 24 Nov 2015, 05:23

Re: Save picture in IrfanView from Excel macro

Post by jolivanes »

Thank you both "heren", aka gentlemen.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save picture in IrfanView from Excel macro

Post by HansV »

:grin:
Best wishes,
Hans

jolivanes
Lounger
Posts: 28
Joined: 24 Nov 2015, 05:23

Re: Save picture in IrfanView from Excel macro

Post by jolivanes »

Hans.
Your solution worked straight out of the box. Thanks

snb
I am struggling with it as it keeps on giving an error message on the "shell" line. Error 53, File not found.

snb
4StarLounger
Posts: 585
Joined: 14 Nov 2012, 16:06

Re: Save picture in IrfanView from Excel macro

Post by snb »

Adapting the path "G:\OF\" ?

Did you check the value of c00 ? F8, (if it can't find the i_view*.exe file)

Maybe environ(18) is windows version dependent.

jolivanes
Lounger
Posts: 28
Joined: 24 Nov 2015, 05:23

Re: Save picture in IrfanView from Excel macro

Post by jolivanes »

Yes, I did both
Changed the 18 to 17.

17 =
Path=C:\Program Files\Microsoft Office 15\Root\Office15\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Toshiba\Bluetooth Toshiba Stack\sys\;C:\Program Files (x86)\Toshiba\Bluetooth Toshiba Stack\sys\x64\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft Office 15\root\Client

jolivanes
Lounger
Posts: 28
Joined: 24 Nov 2015, 05:23

Re: Save picture in IrfanView from Excel macro

Post by jolivanes »

BTW, if I replace this
Changed the 14 to 20 and 21 also.

Code: Select all

c00 = Mid(Environ(17), 14) & "\IrfanView\"
Changed the 14 to 20 and 21 also.
by this, it works like a charm

Code: Select all

c00 = "C:\Program Files (x86)\IrfanView\i_view32.exe"

snb
4StarLounger
Posts: 585
Joined: 14 Nov 2012, 16:06

Re: Save picture in IrfanView from Excel macro

Post by snb »

Alternative:

Code: Select all

Environ("Programfiles")
Can you please show us the result of

Code: Select all

Msgbox Environ("programfiles")

jolivanes
Lounger
Posts: 28
Joined: 24 Nov 2015, 05:23

Re: Save picture in IrfanView from Excel macro

Post by jolivanes »

Sorry snb. I did not get an email message about the post.
My apologies not answering sooner.
C:\Program Files (x86) is the result of "Environ ("ProgramFiles")

This is what works like a charm.

Code: Select all

Sub Save_With_Irfanview_By_snb()
Dim c00 As String
    Select Case Environ("computername")
        Case "DESKTOP"
            c00 = "C:\Program Files\IrfanView\i_view64.exe"
        Case "LAPTOP"
            c00 = "C:\Program Files (x86)\IrfanView\i_view32.exe"
    End Select
    Selection.Copy
    Shell c00 & Dir(c00 & "i_view*.exe") & " /clippaste /convert=C:\Test_Folder\Saved With Irfanview.jpg", 0
    Application.CutCopyMode = False
End Sub

jolivanes
Lounger
Posts: 28
Joined: 24 Nov 2015, 05:23

Re: Save picture in IrfanView from Excel macro

Post by jolivanes »

There was a notice regarding your suggestion but I missed it.

snb
4StarLounger
Posts: 585
Joined: 14 Nov 2012, 16:06

Re: Save picture in IrfanView from Excel macro

Post by snb »

No problem ;)
Could you please be so kind as to test this code ?
Because it can be applied in many more situations than your desktop or laptop.

Code: Select all

Private Sub Cmd31_Click()
  c00 = Environ("programfiles") & "\Irfanview\"
  shell  c00 & dir(c00 & "i_view*.exe") & " /clippaste /convert=C:\Test_Folder\Saved With Irfanview.jpg", 0
end sub

jolivanes
Lounger
Posts: 28
Joined: 24 Nov 2015, 05:23

Re: Save picture in IrfanView from Excel macro

Post by jolivanes »

Good morning (afternoon for you)
That indeed does the trick after "Selection.Copy" has been added.
Again, thank you very much.

snb
4StarLounger
Posts: 585
Joined: 14 Nov 2012, 16:06

Re: Save picture in IrfanView from Excel macro

Post by snb »

@joli

Thank you so much (Baje Dankie).
Your suggestion to use Irfanview is very valuable, since Office VBA is hardly apt to handle graphical elements.

jolivanes
Lounger
Posts: 28
Joined: 24 Nov 2015, 05:23

Re: Save picture in IrfanView from Excel macro

Post by jolivanes »

Now you have me confused (which at times is not very difficult I might say)
Baje Dankie looks like South African!
You know better then I do that copying graphics with Excel can be a hit and miss experience where you end up with an "empty" picture.
Since you and Hans have shown me the way to "copy and save Heaven", I have changed the workbooks to use it instead of the old way with a chart.
Thanks again

snb
4StarLounger
Posts: 585
Joined: 14 Nov 2012, 16:06

Re: Save picture in IrfanView from Excel macro

Post by snb »

It not only looks like .....
But has nothing to do with my native tongue (as can be said of English too).
But it sounds so much 'softer', 'cosier', 'nicer' to say.

jolivanes
Lounger
Posts: 28
Joined: 24 Nov 2015, 05:23

Re: Save picture in IrfanView from Excel macro

Post by jolivanes »

Baie dankie vir alles

Similar problem, as the women say, with "Ik hou van jou". They prefer the nice romantic French, Italian or even German and maybe, if it suits the occasion, English.

But we're getting off the original topic
I sure appreciate the help you guys gave me. Thanks.