Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can I change my code so that it runs correctly in Excel 32Bit & 64Bit?

Posted on 2016-08-23
8
Medium Priority
?
71 Views
Last Modified: 2016-08-24
The following code fails when running in Excel 2010 64Bit
Can you modify the code so that it will run in both 32Bit & 64Bit environments?
Thanks

Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function CloseClipboard Lib "user32" () As Long

Open in new window

0
Comment
Question by:spar-kle
  • 4
  • 4
8 Comments
 
LVL 26

Expert Comment

by:pony10us
ID: 41767212
Normally 32 bit would run on 64 bit but not the other way around however you can try something like this:

'Test for 64 bit version
#If Win64 Then
    Public Declare Function OpenClipboard Lib "user64" (ByVal hwnd As Long) As Long
    Public Declare Function EmptyClipboard Lib "user64" () As Long
    Public Declare Function CloseClipboard Lib "user64" () As Long
#Else
    Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
    Public Declare Function EmptyClipboard Lib "user32" () As Long  
    Public Declare Function CloseClipboard Lib "user32" () As Long
#End If

Open in new window

0
 

Author Comment

by:spar-kle
ID: 41767246
Thanks for your reply, however this still throws up an error.
I've attached a screen shot with the error message.
Error-Message.jpg
0
 
LVL 26

Expert Comment

by:pony10us
ID: 41767258
According to Microsoft, you can ignore the error during the edit.  It isn't accurate.  It should still run okay.

For further information:  https://support.microsoft.com/en-us/kb/983043
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:spar-kle
ID: 41767286
Thank you, however the error occurs when running the code...
0
 
LVL 26

Accepted Solution

by:
pony10us earned 2000 total points
ID: 41767451
Sorry, had to go to a meeting.  Also, I think I see my mistake in the code.

Try:

'Test for 64 bit version
#If Win64 Then
    Public Declare PtrSafe Function OpenClipboard Lib "user64" (ByVal hwnd As Long) As Long
    Public Declare PtrSafe Function EmptyClipboard Lib "user64" () As Long
    Public Declare PtrSafe Function CloseClipboard Lib "user64" () As Long
#Else
    Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
    Public Declare Function EmptyClipboard Lib "user32" () As Long  
    Public Declare Function CloseClipboard Lib "user32" () As Long
#End If

Open in new window

0
 

Assisted Solution

by:spar-kle
spar-kle earned 0 total points
ID: 41768327
Thanks for your answer
I found that I had to amend to "user32" in each instance so that it would work.
PtrSafe in the declaration is the key.
Thanks for your help
0
 

Author Closing Comment

by:spar-kle
ID: 41768328
Appreciate your help
0
 
LVL 26

Expert Comment

by:pony10us
ID: 41768946
Glad to assist.  I wasn't thinking real straight or would have caught my error on "user32" myself.  Glad you figured that part out.  :)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question