Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing JPG 3

Status
Not open for further replies.

scrote

Technical User
Feb 20, 2002
27
0
0
GB
I hope someone can help.
I'm only a very low level VBAer so any solution (if possible) to this needs to be simple so I can understnad.
I need to be able to print single .jpg pictures by clicking on a linked button in Excel. I have over 400 .jpg files that I need to print when required.
I would imagine it would be something like:

Sub cmd1_Click()

File = "C:\text.jpg"

Print.File.DefaultPrinter

end sub[/color blue]

Thanks

Scrote
 
You don't need Excel to do this. There are various batch printing utilities, one is called infranview. It can be run from the command line too.

Paul Rigby
VBA, C#, Delphi
 



Are they all in one folder?

Select them in Windows Explorer and PRINT. Then go have a cup of coffee.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
SkipVoight, paulmatt,

Thanks for the information. Unfortunatly I need to run this process from within Excel - I trying to right a simple process that collects the description from the clipboard, compares with a list in excel then prints the corresponding picture (this is among many other tasks I'm attempting to automate using a single excel environment).

Scrote
 
paulmatt,

I'll give it a try and let you know how it works. I've never used shellexecute before (or similar) but htere is always a first time.

Thanks

Scrote
 
I've used "shell" before to call the command line:

Shell "myapp /aswitch"

But you can also use the winapi shellexecute for more control.

Look in the infranview documentation for details of how to call it.



Paul Rigby
VBA, C#, Delphi
 
As a start, you can get the path of the hyperlinked file via:

Code:
activeworkbook.Sheets (1).range("A1").hyperlinks (1).address

 
Add this in a module to be able to get the short file name:

Code:
   Declare Function GetShortPathName Lib "kernel32" _
      Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
      ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

   Public Function GetShortName(ByVal sLongFileName As String) As String
       Dim lRetVal As Long, sShortPathName As String, iLen As Integer
       'Set up buffer area for API function call return
       sShortPathName = Space(255)
       iLen = Len(sShortPathName)

       'Call the function
       lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
       'Strip away unwanted characters.
       GetShortName = Left(sShortPathName, lRetVal)
   End Function

Then this will print the file that the hyperlink assigned to cell A1 points to on the default printer:

Code:
Shell("cmd /c mspaint /p " & getshortname(application.Sheets (1).range("A1").hyperlinks (1).address))
 
mintjulep,

Excellent - exactly what I was looking for to get me started. Works like a dream.

Scrote
 
mintjulep, well written - consise and clear. Worth a star.

Gerry
 


Likewise! ==> [purple]*[/purple]

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top