64 Bit Error in VBA Code Module

PC User

New Member
Joined
Dec 11, 2012
Messages
32
I obtained a spreadsheet that apparently was developed on a 32 bit Windows system and I'm getting an error when I try to use it. I'm not familiar with this type of system conversion and I'd appreciate someone's help. The error seems to be on a function declaration.
See the attached error.



screenshot.1271.jpg
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Basically 32-bit Declare statements don't work for 64-bit. You need to review all and add PtrSafe to allow them to run in 64-bit.

For example your the first statement Declare Function swc_calc Lib "swedll32.dll" ...…. should become Declare PtrSafe Function swc_calc Lib "swedll32.dll" ....

However, if this is intended to also be run on a 32-bit version then you'll have to do a bit more work.

A good read is <a>https://msdn.microsoft.com/en-us/library/office/ee691831(v=office.14).aspx</a>
 
Upvote 0
I'm still having trouble on making the 32 bit to 64 bit conversion. I followed all the instructions on Microsoft's website that could understand using the PtrSafe and the LongPtr and I still cannot get my code to work. When I compile the module there are no errors, but the functions do not work on the spreadsheet. This doesn't make sense. No errors, but the code doesn't work. The swedll32.dll is in the correct location and it works on Windows 32 bit system, but not on a Windows 64 bit system. So the problem is not with the swedll32.dll. It has to be something in the code module.

I have successfully made a test spreadsheet on a Windows 32 bit system, if anyone wants to see it. Again as you can see the code below has been my attempt to make this Excel 32 bit spreadsheet to work on a Windows 64 bit system.

Can anyone help me with this?

Code:
Option Explicit'
' Swiss Ephemeris Release 1.4  19-apr-1999
'
' Declarations for Visual Basic 5.0
' The DLL file must exist in the same directory as the VB executable, or in a system
' directory where it can be found at runtime
'


Private Declare PtrSafe Function swe_calc Lib "swedll32.dll" _
        Alias "_swe_calc@24" ( _
          ByVal tjd As Double, _
          ByVal ipl As LongPtr, _
          ByVal iflag As LongPtr, _
          ByRef x As Double, _
          ByVal serr As String _
        ) As LongPtr   ' x must be first of six array elements
                    ' serr must be able to hold 256 bytes


Private Declare PtrSafe Function swe_calc_d Lib "swedll32.dll" _
        Alias "_swe_calc_d@20" ( _
          ByRef tjd As Double, _
          ByVal ipl As LongPtr, _
          ByVal iflag As LongPtr, _
          ByRef x As Double, _
          ByVal serr As String _
        ) As LongPtr       ' x must be first of six array elements
                        ' serr must be able to hold 256 bytes


Private Declare PtrSafe Function swe_close Lib "swedll32.dll" _
        Alias "_swe_close@0" ( _
        ) As LongPtr


Private Declare PtrSafe Function swe_close_d Lib "swedll32.dll" _
        Alias "_swe_close_d@4" ( _
          ByVal ivoid As LongPtr _
        ) As LongPtr       ' argument ivoid is ignored


Private Declare PtrSafe Sub swe_cotrans Lib "swedll32.dll" _
        Alias "_swe_cotrans@16" ( _
          ByRef xpo As Double, _
          ByRef xpn As Double, _
          ByVal eps As Double _
        )


Private Declare PtrSafe Function swe_cotrans_d Lib "swedll32.dll" _
        Alias "_swe_cotrans_d@12" ( _
          ByRef xpo As Double, _
          ByRef xpn As Double, _
          ByRef eps As Double _
        ) As LongPtr


Private Declare PtrSafe Sub swe_cotrans_sp Lib "swedll32.dll" _
        Alias "_swe_cotrans_sp@16" ( _
          ByRef xpo As Double, _
          ByRef xpn As Double, _
          ByVal eps As Double _
        )


Private Declare PtrSafe Function swe_cotrans_sp_d Lib "swedll32.dll" _
        Alias "_swe_cotrans_sp_d@12" ( _
          ByRef xpo As Double, _
          ByRef xpn As Double, _
          ByRef eps As Double _
        ) As LongPtr


Private Declare PtrSafe Sub swe_cs2degstr Lib "swedll32.dll" _
        Alias "_swe_cs2degstr@8" ( _
          ByVal t As LongPtr, _
          ByVal s As String _
        )


Private Declare PtrSafe Function swe_cs2degstr_d Lib "swedll32.dll" _
        Alias "_swe_cs2degstr_d@8" ( _
          ByVal t As LongPtr, _
          ByVal s As String _
        ) As LongPtr


Private Declare PtrSafe Sub swe_cs2lonlatstr Lib "swedll32.dll" _
        Alias "_swe_cs2lonlatstr@16" ( _
          ByVal t As LongPtr, _
          ByVal pchar As Byte, _
          ByVal mchar As Byte, _
          ByVal s As String _
        )


Private Declare PtrSafe Function swe_cs2lonlatstr_d Lib "swedll32.dll" _
        Alias "_swe_cs2lonlatstr_d@16" ( _
          ByVal t As LongPtr, _
          ByRef pchar As Byte, _
          ByRef mchar As Byte, _
          ByVal s As String _
        ) As LongPtr


Private Declare PtrSafe Sub swe_cs2timestr Lib "swedll32.dll" _
        Alias "_swe_cs2timestr@16" ( _
          ByVal t As LongPtr, _
          ByVal sep As LongPtr, _
          ByVal supzero As LongPtr, _
          ByVal s As String _
        )


Private Declare PtrSafe Function swe_cs2timestr_d Lib "swedll32.dll" _
        Alias "_swe_cs2timestr_d@16" ( _
          ByVal t As LongPtr, _
          ByVal sep As LongPtr, _
          ByVal supzero As LongPtr, _
          ByVal s As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_csnorm Lib "swedll32.dll" _
        Alias "_swe_csnorm@4" ( _
          ByVal p As LongPtr _
        ) As LongPtr


Private Declare PtrSafe Function swe_csnorm_d Lib "swedll32.dll" _
        Alias "_swe_csnorm_d@4" ( _
          ByVal p As LongPtr _
        ) As LongPtr


Private Declare PtrSafe Function swe_csroundsec Lib "swedll32.dll" _
        Alias "_swe_csroundsec@4" ( _
          ByVal p As LongPtr _
        ) As LongPtr


Private Declare PtrSafe Function swe_csroundsec_d Lib "swedll32.dll" _
        Alias "_swe_csroundsec_d@4" ( _
          ByVal p As LongPtr _
        ) As LongPtr


Private Declare PtrSafe Function swe_d2l Lib "swedll32.dll" _
        Alias "_swe_d2l@8" ( _
        ) As LongPtr


Private Declare PtrSafe Function swe_d2l_d Lib "swedll32.dll" _
        Alias "_swe_d2l_d@4" ( _
        ) As LongPtr


Private Declare PtrSafe Function swe_date_conversion Lib "swedll32.dll" _
        Alias "_swe_date_conversion@28" ( _
          ByVal Year As LongPtr, _
          ByVal Month As LongPtr, _
          ByVal Day As LongPtr, _
          ByVal utime As Double, _
          ByVal cal As Byte, _
          ByRef tjd As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_date_conversion_d Lib "swedll32.dll" _
        Alias "_swe_date_conversion_d@24" ( _
          ByVal Year As LongPtr, _
          ByVal Month As LongPtr, _
          ByVal Day As LongPtr, _
          ByRef utime As Double, _
          ByRef cal As Byte, _
          ByRef tjd As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_day_of_week Lib "swedll32.dll" _
        Alias "_swe_day_of_week@8" ( _
          ByVal jd As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_day_of_week_d Lib "swedll32.dll" _
        Alias "_swe_day_of_week_d@4" ( _
          ByRef jd As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_degnorm Lib "swedll32.dll" _
        Alias "_swe_degnorm@8" ( _
          ByVal jd As Double _
        ) As Double


Private Declare PtrSafe Function swe_degnorm_d Lib "swedll32.dll" _
        Alias "_swe_degnorm_d@4" ( _
          ByRef jd As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_deltat Lib "swedll32.dll" _
        Alias "_swe_deltat@8" ( _
          ByVal jd As Double _
        ) As Double


Private Declare PtrSafe Function swe_deltat_d Lib "swedll32.dll" _
        Alias "_swe_deltat_d@8" ( _
          ByRef jd As Double, _
          ByRef deltat As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_difcs2n Lib "swedll32.dll" _
        Alias "_swe_difcs2n@8" ( _
          ByVal p1 As LongPtr, _
          ByVal p2 As LongPtr _
        ) As LongPtr


Private Declare PtrSafe Function swe_difcs2n_d Lib "swedll32.dll" _
        Alias "_swe_difcs2n_d@8" ( _
          ByVal p1 As LongPtr, _
          ByVal p2 As LongPtr _
        ) As LongPtr


Private Declare PtrSafe Function swe_difcsn Lib "swedll32.dll" _
        Alias "_swe_difcsn@8" ( _
          ByVal p1 As LongPtr, _
          ByVal p2 As LongPtr _
        ) As LongPtr


Private Declare PtrSafe Function swe_difcsn_d Lib "swedll32.dll" _
        Alias "_swe_difcsn_d@8" ( _
          ByVal p1 As LongPtr, _
          ByVal p2 As LongPtr _
        ) As LongPtr


Private Declare PtrSafe Function swe_difdeg2n Lib "swedll32.dll" _
        Alias "_swe_difdeg2n@16" ( _
          ByVal p1 As Double, _
          ByVal p2 As Double _
        ) As Double


Private Declare PtrSafe Function swe_difdeg2n_d Lib "swedll32.dll" _
        Alias "_swe_difdeg2n_d@12" ( _
          ByRef p1 As Double, _
          ByRef p2 As Double, _
          ByRef diff As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_difdegn Lib "swedll32.dll" _
        Alias "_swe_difdegn@16" ( _
          ByVal p1 As Double, _
          ByVal p2 As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_difdegn_d Lib "swedll32.dll" _
        Alias "_swe_difdegn_d@12" ( _
          ByRef p1 As Double, _
          ByRef p2 As Double, _
          ByRef diff As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_fixstar Lib "swedll32.dll" _
        Alias "_swe_fixstar@24" ( _
          ByVal star As String, _
          ByVal tjd As Double, _
          ByVal iflag As LongPtr, _
          ByRef x As Double, _
          ByVal serr As String _
        ) As LongPtr       ' x must be first of six array elements
                        ' serr must be able to hold 256 bytes
                        ' star must be able to hold 40 bytes


Private Declare PtrSafe Function swe_fixstar_d Lib "swedll32.dll" _
        Alias "_swe_fixstar_d@20" ( _
          ByVal star As String, _
          ByRef tjd As Double, _
          ByVal iflag As LongPtr, _
          ByRef x As Double, _
          ByVal serr As String _
        ) As LongPtr       ' x must be first of six array elements
                        ' serr must be able to hold 256 bytes
                        ' star must be able to hold 40 bytes


Private Declare PtrSafe Function swe_get_ayanamsa Lib "swedll32.dll" _
        Alias "_swe_get_ayanamsa@8" ( _
          ByVal tjd_et As Double _
        ) As Double


Private Declare PtrSafe Function swe_get_ayanamsa_d Lib "swedll32.dll" _
        Alias "_swe_get_ayanamsa_d@8" ( _
          ByRef tjd_et As Double, _
          ByRef ayan As Double _
        ) As LongPtr


Private Declare PtrSafe Sub swe_get_planet_name Lib "swedll32.dll" _
        Alias "_swe_get_planet_name@8" ( _
          ByVal ipl As LongPtr, _
          ByVal pname As String _
        )


Private Declare PtrSafe Function swe_get_planet_name_d Lib "swedll32.dll" _
        Alias "_swe_get_planet_name_d@8" ( _
          ByVal ipl As LongPtr, _
          ByVal pname As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_get_tid_acc Lib "swedll32.dll" _
        Alias "_swe_get_tid_acc@0" ( _
        ) As Double


Private Declare PtrSafe Function swe_get_tid_acc_d Lib "swedll32.dll" _
        Alias "_swe_get_tid_acc_d@4" ( _
          ByRef x As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_houses Lib "swedll32.dll" _
        Alias "_swe_houses@36" ( _
          ByVal tjd_ut As Double, _
          ByVal geolat As Double, _
          ByVal geolon As Double, _
          ByVal ihsy As LongPtr, _
          ByRef hcusps As Double, _
          ByRef ascmc As Double _
        ) As LongPtr       ' hcusps must be first of 13 array elements
                        ' ascmc must be first of 10 array elements


Private Declare PtrSafe Function swe_houses_d Lib "swedll32.dll" _
        Alias "_swe_houses_d@24" ( _
          ByRef tjd_ut As Double, _
          ByRef geolat As Double, _
          ByRef geolon As Double, _
          ByVal ihsy As LongPtr, _
          ByRef hcusps As Double, _
          ByRef ascmc As Double _
        ) As LongPtr       ' hcusps must be first of 13 array elements
                        ' ascmc must be first of 10 array elements


Private Declare PtrSafe Function swe_houses_ex Lib "swedll32.dll" _
        Alias "_swe_houses_ex@40" ( _
          ByVal tjd_ut As Double, _
          ByVal iflag As LongPtr, _
          ByVal geolat As Double, _
          ByVal geolon As Double, _
          ByVal ihsy As LongPtr, _
          ByRef hcusps As Double, _
          ByRef ascmc As Double _
        ) As LongPtr       ' hcusps must be first of 13 array elements
                        ' ascmc must be first of 10 array elements


Private Declare PtrSafe Function swe_houses_ex_d Lib "swedll32.dll" _
        Alias "_swe_houses_ex_d@28" ( _
          ByRef tjd_ut As Double, _
          ByVal iflag As LongPtr, _
          ByRef geolat As Double, _
          ByRef geolon As Double, _
          ByVal ihsy As LongPtr, _
          ByRef hcusps As Double, _
          ByRef ascmc As Double _
        ) As LongPtr       ' hcusps must be first of 13 array elements
                        ' ascmc must be first of 10 array elements


Private Declare PtrSafe Function swe_houses_armc Lib "swedll32.dll" _
        Alias "_swe_houses_armc@36" ( _
          ByVal armc As Double, _
          ByVal geolat As Double, _
          ByVal eps As Double, _
          ByVal ihsy As LongPtr, _
          ByRef hcusps As Double, _
          ByRef ascmc As Double _
        ) As LongPtr       ' hcusps must be first of 13 array elements
                        ' ascmc must be first of 10 array elements


Private Declare PtrSafe Function swe_houses_armc_d Lib "swedll32.dll" _
        Alias "_swe_houses_armc_d@24" ( _
          ByRef armc As Double, _
          ByRef geolat As Double, _
          ByRef eps As Double, _
          ByVal ihsy As LongPtr, _
          ByRef hcusps As Double, _
          ByRef ascmc As Double _
        ) As LongPtr       ' hcusps must be first of 13 array elements
                        ' ascmc must be first of 10 array elements


Private Declare PtrSafe Function swe_house_pos Lib "swedll32.dll" _
        Alias "_swe_house_pos@36" ( _
          ByVal armc As Double, _
          ByVal geolat As Double, _
          ByVal eps As Double, _
          ByVal ihsy As LongPtr, _
          ByRef xpin As Double, _
          ByVal serr As String _
        ) As Double
                        ' xpin must be first of 2 array elements


Private Declare PtrSafe Function swe_house_pos_d Lib "swedll32.dll" _
        Alias "_swe_house_pos_d@28" ( _
          ByRef armc As Double, _
          ByRef geolat As Double, _
          ByRef eps As Double, _
          ByVal ihsy As LongPtr, _
          ByRef xpin As Double, _
          ByRef hpos As Double, _
          ByVal serr As String _
        ) As LongPtr
                        ' xpin must be first of 2 array elements


Private Declare PtrSafe Function swe_julday Lib "swedll32.dll" _
        Alias "_swe_julday@24" ( _
          ByVal Year As LongPtr, _
          ByVal Month As LongPtr, _
          ByVal Day As LongPtr, _
          ByVal hour As Double, _
          ByVal gregflg As LongPtr _
        ) As Double


Private Declare PtrSafe Function swe_julday_d Lib "swedll32.dll" _
        Alias "_swe_julday_d@24" ( _
          ByVal Year As LongPtr, _
          ByVal Month As LongPtr, _
          ByVal Day As LongPtr, _
          ByRef hour As Double, _
          ByVal gregflg As LongPtr, _
          ByRef tjd As Double _
        ) As LongPtr


Private Declare PtrSafe Sub swe_revjul Lib "swedll32.dll" _
        Alias "_swe_revjul@28" ( _
          ByVal tjd As Double, _
          ByVal gregflg As LongPtr, _
          ByRef Year As LongPtr, _
          ByRef Month As LongPtr, _
          ByRef Day As LongPtr, _
          ByRef hour As Double _
        )


Private Declare PtrSafe Function swe_revjul_d Lib "swedll32.dll" _
        Alias "_swe_revjul_d@24" ( _
          ByRef tjd As Double, _
          ByVal gregflg As LongPtr, _
          ByRef Year As LongPtr, _
          ByRef Month As LongPtr, _
          ByRef Day As LongPtr, _
          ByRef hour As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_set_sid_mode Lib "swedll32.dll" _
        Alias "_swe_set_sid_mode@20" ( _
          ByVal sid_mode As LongPtr, _
          ByVal t0 As Double, _
          ByVal ayan_t0 As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_set_sid_mode_d Lib "swedll32.dll" _
        Alias "_swe_sid_mode_d@12" ( _
          ByVal sid_mode As LongPtr, _
          ByRef t0 As Double, _
          ByRef ayan_t0 As Double _
        ) As LongPtr


Private Declare PtrSafe Sub swe_set_topo Lib "swedll32.dll" _
        Alias "_swe_set_topo@24" ( _
          ByVal geolon As Double, _
          ByVal geolat As Double, _
          ByVal altitude As Double _
        )


Private Declare PtrSafe Sub swe_set_topo_d Lib "swedll32.dll" _
        Alias "_swe_set_topo_d@12" ( _
          ByRef geolon As Double, _
          ByRef geolat As Double, _
          ByRef altitude As Double _
        )


Private Declare PtrSafe Function swe_lun_eclipse_how Lib "swedll32.dll" _
        Alias "_swe_lun_eclipse_how@24" ( _
          ByVal tjd_ut As Double, _
          ByVal ifl As LongPtr, _
          ByRef geopos As Double, _
          ByRef attr As Double, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_lun_eclipse_how_d Lib "swedll32.dll" _
        Alias "_swe_lun_eclipse_how_d@20" ( _
          ByRef tjd_ut As Double, _
          ByVal ifl As LongPtr, _
          ByRef geopos As Double, _
          ByRef attr As Double, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_lun_eclipse_when Lib "swedll32.dll" _
        Alias "_swe_lun_eclipse_when@28" ( _
          ByVal tjd_start As Double, _
          ByVal ifl As LongPtr, _
          ByVal ifltype As LongPtr, _
          ByRef tret As Double, _
          ByVal backward As LongPtr, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_lun_eclipse_when_d Lib "swedll32.dll" _
        Alias "_swe_lun_eclipse_when_d@24" ( _
          ByRef tjd_start As Double, _
          ByVal ifl As LongPtr, _
          ByVal ifltype As LongPtr, _
          ByRef tret As Double, _
          ByVal backward As LongPtr, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_sol_eclipse_how Lib "swedll32.dll" _
        Alias "_swe_sol_eclipse_how@24" ( _
          ByVal tjd_ut As Double, _
          ByVal ifl As LongPtr, _
          ByRef geopos As Double, _
          ByRef attr As Double, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_sol_eclipse_how_d Lib "swedll32.dll" _
        Alias "_swe_sol_eclipse_how_d@20" ( _
          ByRef tjd_ut As Double, _
          ByVal ifl As LongPtr, _
          ByRef geopos As Double, _
          ByRef attr As Double, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_sol_eclipse_when_glob Lib "swedll32.dll" _
        Alias "_swe_sol_eclipse_when_glob@28" ( _
          ByVal tjd_start As Double, _
          ByVal ifl As LongPtr, _
          ByVal ifltype As LongPtr, _
          ByRef tret As Double, _
          ByVal backward As LongPtr, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_sol_eclipse_when_glob_d Lib "swedll32.dll" _
        Alias "_swe_sol_eclipse_when_glob_d@24" ( _
          ByRef tjd_start As Double, _
          ByVal ifl As LongPtr, _
          ByVal ifltype As LongPtr, _
          ByRef tret As Double, _
          ByVal backward As LongPtr, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_sol_eclipse_when_loc Lib "swedll32.dll" _
        Alias "_swe_sol_eclipse_when_loc@32" ( _
          ByVal tjd_start As Double, _
          ByVal ifl As LongPtr, _
          ByRef tret As Double, _
          ByRef attr As Double, _
          ByVal backward As LongPtr, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_sol_eclipse_when_loc_d Lib "swedll32.dll" _
        Alias "_swe_sol_eclipse_when_loc_d@28" ( _
          ByRef tjd_start As Double, _
          ByVal ifl As LongPtr, _
          ByRef tret As Double, _
          ByRef attr As Double, _
          ByVal backward As LongPtr, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_sol_eclipse_where Lib "swedll32.dll" _
        Alias "_swe_sol_eclipse_where@24" ( _
          ByVal tjd_ut As Double, _
          ByVal ifl As LongPtr, _
          ByRef geopos As Double, _
          ByRef attr As Double, _
          ByVal backward As LongPtr, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_sol_eclipse_where_d Lib "swedll32.dll" _
        Alias "_swe_sol_eclipse_where_d@20" ( _
          ByRef tjd_ut As Double, _
          ByVal ifl As LongPtr, _
          ByRef geopos As Double, _
          ByRef attr As Double, _
          ByVal backward As LongPtr, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_pheno Lib "swedll32.dll" _
        Alias "_swe_pheno@24" ( _
          ByVal tjd As Double, _
          ByVal ipl As LongPtr, _
          ByVal iflag As LongPtr, _
          ByRef attr As Double, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Function swe_pheno_d Lib "swedll32.dll" _
        Alias "_swe_pheno_d@20" ( _
          ByRef tjd As Double, _
          ByVal ipl As LongPtr, _
          ByVal iflag As LongPtr, _
          ByRef attr As Double, _
          ByVal serr As String _
        ) As LongPtr


Private Declare PtrSafe Sub swe_set_ephe_path Lib "swedll32.dll" _
        Alias "_swe_set_ephe_path@4" ( _
          ByVal path As String _
        )


Private Declare PtrSafe Function swe_set_ephe_path_d Lib "swedll32.dll" _
        Alias "_swe_set_ephe_path_d@4" ( _
          ByVal path As String _
        ) As LongPtr


Private Declare PtrSafe Sub swe_set_jpl_file Lib "swedll32.dll" _
        Alias "_swe_set_jpl_file@4" ( _
          ByVal file As String _
        )


Private Declare PtrSafe Function swe_set_jpl_file_d Lib "swedll32.dll" _
        Alias "_swe_set_jpl_file_d@4" ( _
          ByVal file As String _
        ) As LongPtr


Private Declare PtrSafe Sub swe_set_tid_acc Lib "swedll32.dll" _
        Alias "_swe_set_tid_acc@8" ( _
          ByVal x As Double _
        )


Private Declare PtrSafe Function swe_set_tid_acc_d Lib "swedll32.dll" _
        Alias "_swe_set_tid_acc_d@4" ( _
          ByRef x As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_sidtime0 Lib "swedll32.dll" _
        Alias "_swe_sidtime0@24" ( _
          ByVal tjd_ut As Double, _
          ByVal ecl As Double, _
          ByVal nut As Double _
        ) As Double


Private Declare PtrSafe Function swe_sidtime0_d Lib "swedll32.dll" _
        Alias "_swe_sidtime0_d@16" ( _
          ByRef tjd_ut As Double, _
          ByRef ecl As Double, _
          ByRef nut As Double, _
          ByRef sidt As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_sidtime Lib "swedll32.dll" _
        Alias "_swe_sidtime@8" ( _
          ByVal tjd_ut As Double _
        ) As Double


Private Declare PtrSafe Function swe_sidtime_d Lib "swedll32.dll" _
        Alias "_swe_sidtime_d@8" ( _
          ByRef tjd_ut As Double, _
          ByRef sidt As Double _
        ) As LongPtr


Private Declare PtrSafe Function swe_time_equ Lib "swedll32.dll" _
        Alias "_swe_time_equ@16" ( _
          ByVal tjd_ut As Double, _
          ByVal e As Double, _
          ByRef serr As String _
        ) As LongPtr


' planet and body numbers (parameter ipl) for swe_calc()
 Const SE_SUN As Integer = 0
 Const SE_MOON As Integer = 1
 Const SE_MERCURY As Integer = 2
 Const SE_VENUS As Integer = 3
 Const SE_MARS As Integer = 4
 Const SE_JUPITER As Integer = 5
 Const SE_SATURN As Integer = 6
 Const SE_URANUS As Integer = 7
 Const SE_NEPTUNE As Integer = 8
 Const SE_PLUTO   As Integer = 9
 Const SE_MEAN_NODE As Integer = 10
 Const SE_TRUE_NODE As Integer = 11
 Const SE_MEAN_APOG As Integer = 12
 Const SE_OSCU_APOG As Integer = 13
 Const SE_EARTH     As Integer = 14
 Const SE_CHIRON    As Integer = 15
 Const SE_PHOLUS    As Integer = 16
 Const SE_CERES     As Integer = 17
 Const SE_PALLAS    As Integer = 18
 Const SE_JUNO      As Integer = 19
 Const SE_VESTA     As Integer = 20
' Hamburger or Uranian "planets"
 Const SE_CUPIDO As Integer = 40
 Const SE_HADES As Integer = 41
 Const SE_ZEUS As Integer = 42
 Const SE_KRONOS As Integer = 43
 Const SE_APOLLON As Integer = 44
 Const SE_ADMETOS As Integer = 45
 Const SE_VULKANUS As Integer = 46
 Const SE_POSEIDON As Integer = 47
' other ficticious bodies
 Const SE_ISIS As Integer = 48
 Const SE_NIBIRU As Integer = 49
 Const SE_HARRINGTON As Integer = 50
 Const SE_NEPTUNE_LEVERRIER As Integer = 51
 Const SE_NEPTUNE_ADAMS As Integer = 52
 Const SE_PLUTO_LOWELL As Integer = 53
 Const SE_PLUTO_PICKERING As Integer = 54
 
' iflag values for swe_calc() and swe_fixstar()
Const SEFLG_JPLEPH As LongPtr = 1
Const SEFLG_SWIEPH As LongPtr = 2
Const SEFLG_MOSEPH As LongPtr = 4
Const SEFLG_SPEED As LongPtr = 256
Const SEFLG_SPEED3 As LongPtr = 128
Const SEFLG_HELCTR As LongPtr = 8
Const SEFLG_TRUEPOS As LongPtr = 16
Const SEFLG_J2000 As LongPtr = 32
Const SEFLG_NONUT As LongPtr = 64
Const SEFLG_NOGDEFL As LongPtr = 512
Const SEFLG_NOABERR As LongPtr = 1024
Const SEFLG_EQUATORIAL As LongPtr = 2048
Const SEFLG_XYZ As LongPtr = 4096
Const SEFLG_RADIANS As LongPtr = 8192
Const SEFLG_BARYCTR As LongPtr = 16384
Const SEFLG_TOPOCTR As LongPtr = 32768
Const SEFLG_SIDEREAL As LongPtr = 65536


'eclipse codes
Const SE_ECL_CENTRAL As LongPtr = 1
Const SE_ECL_NONCENTRAL As LongPtr = 2
Const SE_ECL_TOTAL As LongPtr = 4
Const SE_ECL_ANNULAR As LongPtr = 8
Const SE_ECL_PARTIAL As LongPtr = 16
Const SE_ECL_ANNULAR_TOTAL As LongPtr = 32
Const SE_ECL_PENUMBRAL As LongPtr = 64
Const SE_ECL_VISIBLE As LongPtr = 128
Const SE_ECL_MAX_VISIBLE As LongPtr = 256
Const SE_ECL_1ST_VISIBLE As LongPtr = 512
Const SE_ECL_2ND_VISIBLE As LongPtr = 1024
Const SE_ECL_3RD_VISIBLE As LongPtr = 2048
Const SE_ECL_4TH_VISIBLE As LongPtr = 4096


'sidereal modes
Const SE_SIDM_FAGAN_BRADLEY    As LongPtr = 0
Const SE_SIDM_LAHIRI           As LongPtr = 1
Const SE_SIDM_DELUCE           As LongPtr = 2
Const SE_SIDM_RAMAN            As LongPtr = 3
Const SE_SIDM_USHASHASHI       As LongPtr = 4
Const SE_SIDM_KRISHNAMURTI     As LongPtr = 5
Const SE_SIDM_DJWHAL_KHUL      As LongPtr = 6
Const SE_SIDM_YUKTESHWAR       As LongPtr = 7
Const SE_SIDM_JN_BHASIN        As LongPtr = 8
Const SE_SIDM_BABYL_KUGLER1    As LongPtr = 9
Const SE_SIDM_BABYL_KUGLER2   As LongPtr = 10
Const SE_SIDM_BABYL_KUGLER3   As LongPtr = 11
Const SE_SIDM_BABYL_HUBER     As LongPtr = 12
Const SE_SIDM_BABYL_ETPSC     As LongPtr = 13
Const SE_SIDM_ALDEBARAN_15TAU As LongPtr = 14
Const SE_SIDM_HIPPARCHOS      As LongPtr = 15
Const SE_SIDM_SASSANIAN       As LongPtr = 16
Const SE_SIDM_GALCENT_0SAG    As LongPtr = 17
Const SE_SIDM_J2000           As LongPtr = 18
Const SE_SIDM_J1900           As LongPtr = 19
Const SE_SIDM_B1950           As LongPtr = 20
Const SE_SIDM_USER            As LongPtr = 255


Const SE_NSIDM_PREDEF         As LongPtr = 21


Const SE_SIDBITS              As LongPtr = 256
'for projection onto ecliptic of t0
Const SE_SIDBIT_ECL_T0        As LongPtr = 256
'for projection onto solar system plane
Const SE_SIDBIT_SSY_PLANE     As LongPtr = 512


Private Function outdeg(x As Double) As String
  Dim fract As Double, min As Integer, sec As Double
  fract = Abs(x) - Int(Abs(x))
  min = Int(fract * 60)
  sec = fract * 3600 - min * 60
  outdeg = Format(Sgn(x) * Int(Abs(x)), "###0") + "°" + Format(min, "00") + "'" + Format(sec, "00.0000")
End Function


Private Function outZdeg(x As Double) As String
  Dim outdegx As Integer
  Dim sign As String
  Dim fract As Double, deg As Integer, min As Integer, sec As Double
  
  fract = Abs(x) - Int(Abs(x))
  deg = Int(Abs(x))
  min = Int(fract * 60)
  sec = fract * 3600 - min * 60
  'outdeg = Format(Sgn(x) * Int(Abs(x)), "###0") + "°" + Format(Min, "00") + "'" + Format(sec, "00.0000")
  
  If deg >= 0 And deg < 30 Then
    sign = "ARI"
    outdegx = deg - 0
  End If
  If deg >= 30 And deg < 60 Then
    sign = "TAU"
    outdegx = deg - 30
  End If
  If deg >= 60 And deg < 90 Then
    sign = "GEM"
    outdegx = deg - 60
  End If
  If deg >= 90 And deg < 120 Then
    sign = "CNC"
    outdegx = deg - 90
  End If
  If deg >= 120 And deg < 150 Then
    sign = "LEO"
    outdegx = deg - 120
  End If
  If deg >= 150 And deg < 180 Then
  sign = "VIR"
    outdegx = deg - 150
  End If
  If deg >= 180 And deg < 210 Then
    sign = "LIB"
    outdegx = deg - 180
  End If
  If deg >= 210 And deg < 240 Then
    sign = "SCO"
    outdegx = deg - 210
  End If
  If deg >= 240 And deg < 270 Then
    sign = "SGR"
    outdegx = deg - 240
  End If
  If deg >= 270 And deg < 300 Then
    sign = "CAP"
    outdegx = deg - 270
  End If
  If deg >= 300 And deg < 330 Then
    sign = "AQU"
    outdegx = deg - 300
  End If
  If deg >= 330 And deg < 360 Then
    sign = "PSC"
    outdegx = deg - 330
  End If
  
  outZdeg = Format(outdegx, "00") & "°" & sign & " " & Format(min, "00") & "' " & Format(sec, "00") & "''"
  
End Function


Public Function Planet_Location( _
   y As LongPtr, _
   m As LongPtr, _
   d As LongPtr, _
   h As Double, _
   latitude As Double, _
   longitude As Double, _
   altitude As Double, _
   tz As Double, _
   planet As LongPtr, _
   coord As Integer) _
As Double


Dim jul_day_UT As Double, jul_day_ET As Double, x(6) As Double
Dim i As LongPtr, iflag As LongPtr, serr As String
'Dim longitude As LongPtr, latitude As LongPtr, altitude As LongPtr


    Select Case coord
        Case Is = 0
            iflag = SEFLG_SIDEREAL + SEFLG_SPEED
            i = swe_set_sid_mode(SE_SIDM_LAHIRI, 0#, 0#)
        Case Is = 1
            iflag = SEFLG_HELCTR + SEFLG_SPEED
        Case Is = 2
            iflag = SEFLG_TOPOCTR + SEFLG_SPEED
            swe_set_topo longitude, latitude, tz
    End Select


   jul_day_UT = swe_julday(y, m, d, h, 1) + tz / 24#
   jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT)
   'iflag = SEFLG_SIDEREAL
   i = swe_calc(jul_day_ET, planet, iflag, x(0), serr)
   Planet_Location = x(0)


End Function




Private Function ZodiacSign(x As Double) As String
  Dim outdegx As Integer
  Dim sign As String
  Dim fract As Double, deg As Integer, min As Integer, sec As Double
  
  fract = Abs(x) - Int(Abs(x))
  deg = Int(Abs(x))
  min = Int(fract * 60)
  sec = fract * 3600 - min * 60
  
  
  If deg >= 0 And deg < 30 Then
    sign = "Aries"
    outdegx = deg - 0
  End If
  If deg >= 30 And deg < 60 Then
    sign = "Taurus"
    outdegx = deg - 30
  End If
  If deg >= 60 And deg < 90 Then
    sign = "Gemini"
    outdegx = deg - 60
  End If
  If deg >= 90 And deg < 120 Then
    sign = "Cancer"
    outdegx = deg - 90
  End If
  If deg >= 120 And deg < 150 Then
    sign = "Leo"
    outdegx = deg - 120
  End If
  If deg >= 150 And deg < 180 Then
  sign = "Virgo"
    outdegx = deg - 150
  End If
  If deg >= 180 And deg < 210 Then
    sign = "Libra"
    outdegx = deg - 180
  End If
  If deg >= 210 And deg < 240 Then
    sign = "Scorpio"
    outdegx = deg - 210
  End If
  If deg >= 240 And deg < 270 Then
    sign = "Sagittarius"
    outdegx = deg - 240
  End If
  If deg >= 270 And deg < 300 Then
    sign = "Capricorn"
    outdegx = deg - 270
  End If
  If deg >= 300 And deg < 330 Then
    sign = "Aquarius"
    outdegx = deg - 300
  End If
  If deg >= 330 And deg < 360 Then
    sign = "Pisces"
    outdegx = deg - 330
  End If
  
  ZodiacSign = sign
  
End Function
 
Last edited:
Upvote 0
Are you sure the dll is actually 64bit compatible?

By the way, you don't just change all Longs into LongPtr - that only needs doing to handles/pointers.
 
Upvote 0
I obtained both the 32 bit and the 64 bit Swiss Ephemeris dll and copied them to all appropriate folders to ensure that Excel would find it. The spreadsheet does not work. I tried with Long and LongPtr and the spreadsheet doesn't work.
 
Last edited:
Upvote 0
What exactly does "doesn't work" mean?
 
Upvote 0
Doesn't work means that the formulas in the cells do not calculate any values (aka results). The cells that should contain functions from the code module do not produce any results (aka they produce errors). These same cells on Excel 32 bit running on Windows 32 bit do produce correct results with the functions from the code modules. The cells on Excel 32 bit running on Windows 64 bit produce errors even though I have modified the functions in the code module as per instructions on the Microsoft website for adapting VBA in Excel 32 bit for Windows 64 bit. I have followed Microsoft instructions and the modified functions in the code module do not produce compilation errors, never the less the functions in the code modules for Excel 32 bit when used on the spreadsheet only produce errors on a Windows 64 bit system.

To clarify again. I have followed the instructions on the Microsoft website to adapt the functions in the code module in order to make this Excel 32 bit file work (produce results and not errors) and it failed. What I mean by "does not work" is that it does not produce expected results, but only errors. The functions produce errors when used on the spreadsheet.

What exactly does "doesn't work" mean?
 
Upvote 0
Excel 32bit should not require any modification of the code. Only 64bit Office requires use of Ptrsafe and Longptr.
 
Upvote 0
I'm guessing your issue is caused by Excel unable to find a 64bit DLL. Is your 64bit dll named swedll32.dll or swedll64.dll? That I suspect could be your problem.

A quick Google search suggests visiting ftp://ftp.astro.com/pub/swisseph and download swe_dlls_2.05.zip which seems to contain the 32 & 64 bit DLL you may need.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top