Solved

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

Posted on 2016-08-23
8
53 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

705 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