Consulting

Results 1 to 6 of 6

Thread: Solved: Printing a *.gif file from a command button depending a cell value

  1. #1
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location

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

    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.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    An easy way is to insert it to a sheet and print it, then delete it. An example recording it.
    [VBA] 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[/VBA]

  3. #3
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Thanks Ken
    I will try it tonight and let you know.

  4. #4
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    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 ?

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA] 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[/VBA]

  6. #6
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location

    Printing Picture from a command button

    Hi Ken,

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

    Rob

Posting Permissions

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