Option Explicit
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" _
(ByVal lpFileName As String) As Long
'\Lets Use a Constant
Public Const MyLogo = "C:\temp\MyLogo.Emf"
Sub test()
Dim fNum As Integer ' Hold next File#
' Byte arrays to hold the PictureData prop
' Example grabs Image1 from Form: MyLogo
' Original Code and Credit to Stephen Lebans
' Tweaked by Nate Oliver
Dim bArray() As Byte, cArray() As Byte
Dim lngRet As Long
' Excel & pic late bind vars
Dim myPic As Object, myXl As Object
DoCmd.Echo False, "Hold Up"
DoCmd.OpenForm "MyLogo", acNormal, , , acFormEdit
' Resize to hold entire PictureData prop
ReDim bArray(LenB(Forms!MyLogo.Image1.PictureData) - 1)
' Resize to hold the EMF wrapped in the PictureData prop
ReDim cArray(LenB(Forms!MyLogo.Image1.PictureData) - (1 + 8))
' Copy to our array
bArray = Forms!MyLogo.Image1.PictureData
DoCmd.Close acForm, "MyLogo", acSaveNo
DoCmd.Echo True, False
' Copy the embedded EMF - SKIP first 8 bytes
For lngRet = 8 To UBound(cArray) ' - (1) '+ 8)
cArray(lngRet - 8) = bArray(lngRet)
Next
' Get next avail file handle
fNum = FreeFile
' Let's Create/Open our new EMF File.
Open MyLogo For Binary As fNum
' Write out the EMF FileHeader
Put fNum, , cArray
' Close the File
Close fNum
Set myXl = GetObject(, "Excel.Application")
Set myPic = myXl.sheets(2).Pictures.Insert(MyLogo)
With myPic
.Top = myXl.sheets(2).[g4].Top
.ShapeRange.Height = myXl.sheets(2).[g4].RowHeight * 6.2 '6.2 rows tall
.Left = myXl.sheets(2).[g4].Left - .Width 'Right align at G
End With
Call DeleteFile(MyLogo)
End Sub