PDA

View Full Version : Print file using commandbutton



Johnpants
11-15-2005, 04:22 AM
I'm not sure if this is possible, and not to worry if it isn't it's just something that would be nice to have.

I would like to have a commandbutton that when clicked prints a Jpeg image.

The file is called 'Sales form Print' and is in the same directory as the Excel workbook.

Am I hoping too much or is this a simple thing to do?

Thanks,

john.

Killian
11-15-2005, 09:24 AM
I don't think it's too much to ask...
You need to set up a shell application object and give it the file and the print command.
Here's an example - bear in mind it will error if it can't find the filename but that's easily fixed if it's an issueSub PrintFile()

Dim objShellApp As Object
Dim objFolder As Object
Dim strFileName As String

strFileName = "Picture 1.gif"

Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.Namespace(ThisWorkbook.Path)

objFolder.ParseName(strFileName).InvokeVerb ("&Print")

End Sub