Solved

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

Posted on 2016-08-23
8
45 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

730 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