Solved

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

Posted on 2016-08-23
8
33 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
 

Author Comment

by:spar-kle
ID: 41767286
Thank you, however the error occurs when running the code...
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Query Missing Money orders... 6 73
Excel formula 6 23
integer8 values 1 10
Redacting a row in Excel based on a term. 17 36
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now