PDA

View Full Version : Solved: Printing a *.gif file from a command button depending a cell value



Rob342
04-09-2009, 05:10 AM
Hi Everyone
This is my 1st post & have recently just joined VBAX, i am a bit of a newbie to vba and would be gratefull for some help.
I am working on a excel spread sheet and would like to print a *.gif file image when a user selects a command button on a sheet, depending on what value for example cell J5 holds to what picture is printed.
I have searched all the various forums but have not found anything to actually print a gif file using vba ?
Any help would be most appreciated.
:banghead:

Kenneth Hobs
04-09-2009, 07:16 AM
Welcome to the forum!

An easy way is to insert it to a sheet and print it, then delete it. An example recording it.
Sheets("Sheet2").Select
ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\Ken\My Documents\My Pictures\Ken.jpg").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Selection.Delete
Sheets("Sheet1").Select

Rob342
04-09-2009, 08:29 AM
Thanks Ken
I will try it tonight and let you know.

Rob342
04-16-2009, 04:18 AM
Thanks Ken
Sorry for the delay have been away for Easter.
That works ok, is there any other way that this can be done without showing the 2 sheet for example when a user hits the print command box it will just print the picture without displaying the 2 sheet & picture or is it possible to just hide it ?

Kenneth Hobs
04-16-2009, 05:42 AM
Dim sPic As String, pObj As Object
Application.ScreenUpdating = False
sPic = "x:\pics\Ken.jpg"
With Worksheets("Sheet2")
Set pObj = .Pictures.Insert(sPic)
.PrintOut Copies:=1, Collate:=True
pObj.Delete
End With
Application.ScreenUpdating = True

Rob342
04-16-2009, 06:47 AM
Hi Ken,

What can i say your an absolute genius, thats exactly what i was looking for. Thankyou for your time and help

Rob