Private
Declare
PtrSafe
Function
IsClipboardFormatAvailable
Lib
"user32"
(
ByVal
wFormat
As
Integer
)
As
Long
Private
Declare
PtrSafe
Function
OpenClipboard
Lib
"user32"
(
ByVal
hwnd
As
Long
)
As
Long
Private
Declare
PtrSafe
Function
GetClipboardData
Lib
"user32"
(
ByVal
wFormat
As
Integer
)
As
Long
Private
Declare
PtrSafe
Function
CloseClipboard
Lib
"user32"
()
As
Long
Private
Declare
PtrSafe
Function
OleCreatePictureIndirect
Lib
"oleaut32.dll"
(PicDesc
As
uPicDesc, RefIID
As
GUID,
ByVal
fPictureOwnsHandle
As
Long
, IPic
As
IPicture)
As
Long
Declare
PtrSafe
Function
CopyEnhMetaFile
Lib
"gdi32"
Alias
"CopyEnhMetaFileA"
(
ByVal
hemfSrc
As
Long
,
ByVal
lpszFile
As
String
)
As
Long
Declare
PtrSafe
Function
CopyImage
Lib
"user32"
(
ByVal
handle
As
Long
,
ByVal
un1
As
Long
,
ByVal
n1
As
Long
,
ByVal
n2
As
Long
,
ByVal
un2
As
Long
)
As
Long
Private
Declare
PtrSafe
Sub
keybd_event
Lib
"user32"
(
ByVal
bVk
As
Byte
,
ByVal
bScan
As
Byte
,
ByVal
dwFlags
As
Long
,
ByVal
dwExtraInfo
As
Long
)
Private
Type GUID
Data1
As
Long
Data2
As
Integer
Data3
As
Integer
Data4(0
To
7)
As
Byte
End
Type
Private
Type uPicDesc
Size
As
Long
Type
As
Long
hPic
As
Long
hPal
As
Long
End
Type
Const
CF_BITMAP = 2
Const
CF_PALETTE = 9
Const
CF_ENHMETAFILE = 14
Const
IMAGE_BITMAP = 0
Const
LR_COPYRETURNORG = &H4
Private
Const
KEYEVENTF_KEYUP = &H2
Private
Const
VK_SNAPSHOT = &H2C
Private
Const
VK_MENU = &H12
Sub
InlineShape_Speichern()
Dim
iShape
As
InlineShape
Set
iShape = wdDoc.Tables(1).Range.Rows(iRows).Cells(1).Range.InlineShapes(1)
sFolder =
"E:\Fotos"
sFile =
"Foto_"
& iRows &
".bmp"
iShape.Range.CopyAsPicture
SavePicture PastePicture, sFolder & "\" & sFile
End
Sub
Function
PastePicture()
As
IPicture
Dim
h
As
Long
, hPtr
As
Long
, hPal
As
Long
, lPicType
As
Long
, hCopy
As
Long
If
IsClipboardFormatAvailable(CF_BITMAP)
Then
h = OpenClipboard(0&)
If
h > 0
Then
hPtr = GetClipboardData(CF_BITMAP)
hCopy = CopyImage(hPtr, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)
h = CloseClipboard
If
hPtr <> 0
Then
Set
PastePicture = CreatePicture(hCopy, 0, CF_BITMAP)
End
If
End
If
End
Function
Private
Function
CreatePicture(
ByVal
hPic
As
Long
,
ByVal
hPal
As
Long
,
ByVal
lPicType)
As
IPicture
Dim
r
As
Long
, uPicInfo
As
uPicDesc, IID_IDispatch
As
GUID, IPic
As
IPicture
Const
PICTYPE_BITMAP = 1
Const
PICTYPE_ENHMETAFILE = 4
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
With
uPicInfo
.Size = Len(uPicInfo)
.Type = PICTYPE_BITMAP
.hPic = hPic
.hPal = hPal
End
With
r = OleCreatePictureIndirect(uPicInfo, IID_IDispatch,
True
, IPic)
If
r <> 0
Then
Debug.Print
"Create Picture: "
& fnOLEError(r)
Set
CreatePicture = IPic
End
Function
Private
Function
fnOLEError(lErrNum
As
Long
)
As
String
Const
E_ABORT = &H80004004
Const
E_ACCESSDENIED = &H80070005
Const
E_FAIL = &H80004005
Const
E_HANDLE = &H80070006
Const
E_INVALIDARG = &H80070057
Const
E_NOINTERFACE = &H80004002
Const
E_NOTIMPL = &H80004001
Const
E_OUTOFMEMORY = &H8007000E
Const
E_POINTER = &H80004003
Const
E_UNEXPECTED = &H8000FFFF
Const
S_OK = &H0
Select
Case
lErrNum
Case
E_ABORT
fnOLEError =
" Aborted"
Case
E_ACCESSDENIED
fnOLEError =
" Access Denied"
Case
E_FAIL
fnOLEError =
" General Failure"
Case
E_HANDLE
fnOLEError =
" Bad/Missing Handle"
Case
E_INVALIDARG
fnOLEError =
" Invalid Argument"
Case
E_NOINTERFACE
fnOLEError =
" No Interface"
Case
E_NOTIMPL
fnOLEError =
" Not Implemented"
Case
E_OUTOFMEMORY
fnOLEError =
" Out of Memory"
Case
E_POINTER
fnOLEError =
" Invalid Pointer"
Case
E_UNEXPECTED
fnOLEError =
" Unknown Error"
Case
S_OK
fnOLEError =
" Success!"
End
Select
End
Function