Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Out of Memory Error in Excel 2007 but OK in 2003 - Please help.

Hi,

I am trying to execute a code which should save a range of cells as
image.

Here is the code:

Option Explicit

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

'\\ 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 Const CF_BITMAP = 2
Private Const PICTYPE_BITMAP = 1

Private Function SaveRangePic(SourceRange As Range, FilePathName As
String)


Dim IID_IDispatch As GUID
Dim uPicinfo As uPicDesc
Dim IPic As IPicture
Dim hPtr As Long

'\\ Copy Range to ClipBoard
SourceRange.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
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 Range Picture Object
OleCreatePictureIndirect uPicinfo, IID_IDispatch, True, IPic

'\\ Save Picture Object
stdole.SavePicture IPic, FilePathName <<<<<<< FAILS HERE IN 2007

End Function

When I am using Excel 2003, the code works fine. But if I use Excel
2007, I get "Out of Memory" error in the last line of the code which I
have marked.

What could be the reason? or do I need to modify the lines? Help me
out.

Thanks
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time error 1004 since upgrading from Excel 2003 to 2007. PJ Excel Programming 1 July 23rd 08 11:55 PM
Hyperlink error from Excel 2003 to Word 2007 Bobby[_2_] Links and Linking in Excel 1 June 5th 08 03:48 PM
Error on opening Excel 2007(.xlsx) on office 2003 machine. voidshyam Excel Programming 0 February 25th 08 09:51 AM
Excel 2003 converted to 2007 copying worksheet error MAC Excel Discussion (Misc queries) 0 September 6th 07 08:16 PM
Any different between Excel 2007 and 2003 on formula memory? Eric Excel Discussion (Misc queries) 1 September 6th 07 04:55 AM


All times are GMT +1. The time now is 04:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"