+ Reply to Thread
Results 1 to 5 of 5

Get Workbook comaptible with 64 bit

Hybrid View

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Get Workbook comaptible with 64 bit

    Hello everybody
    I have tried a lot in the following file to make it work with 64 bit but I didn't succeed at all
    Here's the attachment ..
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Get Workbook comaptible with 64 bit

    This is my try
    'Requires a reference to the "OLE Automation" type library
    
    '----------------------------------------------------------------------------
    ' User-Defined Type for API Calls
    '----------------------------------------------------------------------------
    
    'Declare a Type 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 Type to store the bitmap information
    'Private Type uPicDesc
    '    Size As Long
    '    Type As Long
    '    hPic As Long
    '    hPal As Long
    'End Type
    
    
    '----------------------------------------------------------------------------
    'Windows API Function Declarations
    '----------------------------------------------------------------------------
    
    
    #If VBA7 Then
    'Does the clipboard contain a Metafile Picture?
    Private Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
    
    'Open the Clipboard
    Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As LongPtr) As Long
    
    'Get a handle on the Picture
    Private Declare PtrSafe Function GetClipboardData Lib "user32" Alias "GetClipboardDataA" (ByVal wFormat As Long) As Long
    
    'Create a copy of the metafile
    Private Declare PtrSafe Function CopyEnhMetaFile Lib "gdi32" Alias "CopyEnhMetaFileA" (ByVal hemfSrc As LongPtr, ByVal lpszFile As String) As Long
    
    'Close the clipboard
    Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
    
    'Convert the handle into an OLE IPicture interface.
    'Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As uPicDesc, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
    'Private Declare PtrSafe Function OleCreatePictureIndirect Lib "oleaut32.dll" (PicDesc As PICTDESC, RefIID As GUID, ByVal fPictureOwnsHandle As LongPtr, IPic As IPicture) As LongPtr
    Private Declare PtrSafe Function OleCreatePictureIndirect Lib "oleaut32.dll" (PicDesc As PICTDESC, RefIID As GUID, ByVal fPictureOwnsHandle As LongPtr, IPic As IPicture) As Long
    
    Private Type PICTDESC
        Size As Long
        Type As Long
        hPic As LongPtr
        hPal As LongPtr
    End Type
    
    #Else
    
    
    
    'Does the clipboard contain a Metafile Picture?
    Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Integer) As Long
    
    'Open the Clipboard
    Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
    
    'Get a handle on the Picture
    Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Integer) As Long
    
    'Create a copy of the metafile
    Private Declare Function CopyEnhMetaFile Lib "gdi32" Alias "CopyEnhMetaFileA" (ByVal hemfSrc As Long, ByVal lpszFile As String) As Long
    
    'Close the clipboard
    Private Declare Function CloseClipboard Lib "user32" () As Long
    
    'Convert the handle into an OLE IPicture interface.
    'Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As uPicDesc, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
    Private Declare Function OleCreatePictureIndirect Lib "oleaut32.dll" (PicDesc As PICTDESC, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
    
    Private Type PICTDESC
        Size As Long
        Type As Long
        hPic As Long
        hPal As Long
    End Type
    #End If
    
    
    Function PastePicture() As IPicture
    
    Const lMETAFILE As Long = 14
    
    Dim lPictureAvailable As Long
    Dim lClipHandle As Long
    Dim lPicHandle As Long
    Dim lCopyHandle As Long
    Dim uInterGUID As GUID
    Dim uPictureInfo As PICTDESC
    Dim lOLEHandle As Long
    Dim iTempPicture As IPicture
    
        'Check if the clipboard contains a picture file
        lPictureAvailable = IsClipboardFormatAvailable(lMETAFILE)
        
        If lPictureAvailable <> 0 Then
            
            'Get a Handle on the Clipboard
            lClipHandle = OpenClipboard(0&)
            
            If lClipHandle > 0 Then
                
                'Get a Handle on the Picture
                 lPicHandle = GetClipboardData(lMETAFILE)
                 
                 'Make a local copy, in case the clipboard is changed
                 lCopyHandle = CopyEnhMetaFile(lPicHandle, vbNullString)
                 
                'Release Handle from Clipboard
                lClipHandle = CloseClipboard
                
                'Only Continue if we have a handle on the Picture
                If lPicHandle <> 0 Then
                    
                    ' Create the Interface GUID (for the IPicture interface)
                    With uInterGUID
                        .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 UPictureInfo with necessary parts.
                    With uPictureInfo
                        .Size = Len(uPictureInfo)   ' Length of structure.
                        .Type = 4                   ' Type of Picture = Metafile
                        .hPic = lCopyHandle         ' Handle to image.
                        .hPal = 0                   ' Handle to palette.
                    End With
                    
                    'Create the IPicture Object
                    lOLEHandle = OleCreatePictureIndirect(uPictureInfo, uInterGUID, True, iTempPicture)
                    
                    If lOLEHandle = 0 Then
                        Set PastePicture = iTempPicture
                    End If
                End If
            End If
        End If
    End Function
    But when intialize the userform got error
    01.png

  3. #3
    Registered User
    Join Date
    12-14-2012
    Location
    Czech Republic
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Get Workbook comaptible with 64 bit

    Hello,

    when run the macro I don't receive any error. The chart's data get changed and picture of chart is displayed in userform...

    sysss

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Get Workbook comaptible with 64 bit

    Thanks syss for reply
    Are you using 64bit ?
    In fact I am using Windows 10 64 Bit and office 2013 64 Bit?

  5. #5
    Registered User
    Join Date
    12-14-2012
    Location
    Czech Republic
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Get Workbook comaptible with 64 bit

    OK. I have Windows 7 64bit and thought, until now, Office 64bit as well. But checked it I have 32bit 2010 MS Office.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Assign name to Workbook, Copy range from one workbook to another workbook
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-18-2015, 03:40 AM
  2. [SOLVED] VBA to open new workbook and run macro from new workbook, which closes old workbook
    By Rerock in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-26-2014, 10:45 AM
  3. [SOLVED] Code to cut cell from one workbook, close same workbook, and paste in different workbook
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 03-13-2014, 04:01 PM
  4. Copy data one workbook to another workbook without opening workbook
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-04-2014, 11:28 AM
  5. [SOLVED] Copy Values From Each Workbook in Folder to a Single Sheet in New Workbook +Workbook names
    By Arsham24 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-21-2012, 07:42 PM
  6. Save an open workbook, then open template workbook and close the saved workbook
    By ondvirg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 10:20 PM
  7. Replies: 1
    Last Post: 04-01-2006, 03:50 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