chipbite / JiraToExcel

Importer of data from jira into excel. Single file excel template.
8 stars 3 forks source link

Fix for not working on 64 bit Excel #6

Open f-steff opened 6 years ago

f-steff commented 6 years ago

Here's a quick fix for making it work on 64 bit Excel. I haven't had time to really dig in and see if this is the full fix, but at least the code is running with this change.

Edit the top to the UsefulStuff Module down to and not including "Public Const cFailedtoGetHandle = -1" line :

Option Explicit
' note original execute shell stuff came from this post
' http://stackoverflow.com/questions/3166265/open-an-html-page-in-default-browser-with-vba
' thanks to http://stackoverflow.com/users/174718/dmr
' Updated to support 64 bit excel, based on https://stackoverflow.com/questions/5506912/how-should-i-make-my-vba-code-compatible-with-64-bit-windows
#If Win64 Then
    Private Declare PtrSafe Function ShellExecute _
       Lib "shell32.dll" Alias "ShellExecuteA" ( _
       ByVal hwnd As Long, _
       ByVal lpOperation As String, _
       ByVal lpFile As String, _
       ByVal lpParameters As String, _
       ByVal lpDirectory As String, _
       ByVal nShowCmd As Long _
       ) As Long
#Else
    Private Declare Function ShellExecute _
       Lib "shell32.dll" Alias "ShellExecuteA" ( _
       ByVal hwnd As Long, _
       ByVal lpOperation As String, _
       ByVal lpFile As String, _
       ByVal lpParameters As String, _
       ByVal lpDirectory As String, _
       ByVal nShowCmd As Long _
       ) As Long
#End If

' note Acknowledgement URI encode stuff came from this post
' http://stackoverflow.com/questions/218181/how-can-i-url-encode-a-string-in-excel-vba
' thanks to http://stackoverflow.com/users/4023/matthew-murdoch
' Updated to support 64 bit excel, https://stackoverflow.com/questions/21982682/code-does-not-work-on-64-bit-office
Private Const CP_UTF8 = 65001
#If Win64 Then
    Private Declare PtrSafe Function WideCharToMultiByte Lib "Kernel32" ( _
       ByVal CodePage As LongPtr, ByVal dwflags As LongPtr, _
       ByVal lpWideCharStr As LongPtr, ByVal cchWideChar As LongPtr, _
       ByVal lpMultiByteStr As LongPtr, ByVal cchMultiByte As LongPtr, _
       ByVal lpDefaultChar As LongPtr, ByVal lpUsedDefaultChar As LongPtr) As LongPtr
#Else
    Private Declare Function WideCharToMultiByte Lib "kernel32" ( _
        ByVal CodePage As Long, ByVal dwflags As Long, _
        ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, _
        ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, _
        ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
#End If
chipbite commented 6 years ago

Thanks @f-steff!

Incidentally, I am back using jira, but have not had the need for this script again, as of yet. If I open it up, will include this change.

Of course, I'd be happy to accept a PR with this change, if you have tested it (preferably on both 32 and 64 bit).

f-steff commented 6 years ago

I don't really know how to make a PR, as the xlsm file (to the best of my knowledge) is considered a binary blob. And unfortunately I do not have access to any 32 bit versions of Excel, so I can't really verify it. Hopefully others can verify on 32 bit, and then you can make the change?