?
Solved

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

Posted on 2016-08-23
8
Medium Priority
?
59 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

765 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