Results 1 to 3 of 3

Save Images Using File Names From Column

Threaded View

  1. #1
    Registered User
    Join Date
    02-07-2016
    Location
    Canada
    MS-Off Ver
    13
    Posts
    65

    Lightbulb Save Images Using File Names From Column

    Hi! I have code to save images based on names from the column:
    'http://www.ozgrid.com/forum/showthread.php?t=43380
    'Many thanks to Jaafar on the Mr. Excel forum for this code.
     '***********************************************************
     
     'Declare a UDT to store a GUID for the IPicture OLE Interface
    Private Type GUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(0 To 7) As Byte
    End Type
     
     'Declare a UDT to store the bitmap information
    Private Type uPicDesc
        Size As Long
        Type As Long
            hPic As Long
            hPal As Long
        End Type
         
        Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
         
        Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Integer) As Long
         
        Private Declare Function CloseClipboard Lib "user32" () As Long
         
        Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" _
        (PicDesc As uPicDesc, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
         
        Const CF_BITMAP = 2
        Const CF_PALETTE = 9
        Const IMAGE_BITMAP = 0
        Const LR_COPYRETURNORG = &H4
        Const PICTYPE_BITMAP = 1
        Dim strPictureFile As String
         
        Sub SaveSelectionAsBMP()
             
            Dim oImageIcon As CommandBarControl
            Dim intFaceId As Integer
            Dim IID_IDispatch As GUID
            Dim uPicinfo As uPicDesc
            Dim IPic As IPicture
            Dim hPtr As Long
            Dim FilePathName As Variant
             
            For Each sh In ActiveSheet.Shapes
            sh.Select
            filename = Sheet1.Range("b" & sh.TopLeftCell.Row).Value ' sorry! change "a" to "b"
            Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
            strPictureFile = "C:\Pics\" & filename & ".jpg"
            'strPictureFile = Application.GetSaveAsFilename("", "JPEG Files (*.jpeg), *.jpeg", , "Save as JPEG")
            If strPictureFile = "False" Then Exit Sub
             
            OpenClipboard 0
            hPtr = GetClipboardData(CF_BITMAP)
            CloseClipboard
             
             'Create the interface GUID for the picture
            With IID_IDispatch
                .Data1 = &H7BF80980
                .Data2 = &HBF32
                .Data3 = &H101A
                .Data4(0) = &H8B
                .Data4(1) = &HBB
                .Data4(2) = &H0
                .Data4(3) = &HAA
                .Data4(4) = &H0
                .Data4(5) = &H30
                .Data4(6) = &HC
                .Data4(7) = &HAB
            End With
             
             '  Fill uPicInfo with necessary parts.
            With uPicinfo
                .Size = Len(uPicinfo) ' Length of structure.
                .Type = PICTYPE_BITMAP ' Type of Picture
                .hPic = hPtr ' Handle to image.
                .hPal = 0 ' Handle to palette (if bitmap).
            End With
             
             'Create the Picture Object
            OleCreatePictureIndirect uPicinfo, IID_IDispatch, True, IPic
             
             'Save Picture
            
            Debug.Print strPictureFile
            SavePicture IPic, strPictureFile
             
             'fix the clipboard (it seems to go messed up)
            Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
           Next
        End Sub
    However, I don't know how to adjust it for it to save images.
    I have an Excel file which includes pictures in column A and I would like to export them into several files as .jpg. The name of the file should be generated from text in column B.
    Can someone help me with this?
    Thanks a lot!
    Last edited by R12345; 02-12-2016 at 06:42 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 10-17-2017, 12:23 AM
  2. [SOLVED] Need to loop a macro to save images to file - but save to user defined directory.
    By superfurry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2015, 07:49 AM
  3. import file names from images
    By visionwindowfilms in forum Excel General
    Replies: 15
    Last Post: 05-07-2014, 05:54 AM
  4. Replies: 3
    Last Post: 12-16-2012, 03:22 PM
  5. [SOLVED] Student names in column save as text file to folder on c: Drive
    By excelaron in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-31-2012, 01:35 PM
  6. Save a file with images in it. Not links!
    By DNAcombo in forum Excel General
    Replies: 0
    Last Post: 05-31-2011, 10:07 AM
  7. Replies: 1
    Last Post: 08-20-2010, 11:12 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1