Compile error in hidden module

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
My client has the following error on their PC:

Code:
Compile error in hidden module: ModURL.

This error commonly occurs when code  is incompatible with the version, platform , or architecture of this application.


This is ModURL:

Code:
Option Explicit

    Public Declare Function InternetGetConnectedState Lib "wininet.dll" (lpdwFlags As Long, ByVal dwReserved As Long) As Boolean

Function URL() As Boolean

    Dim WebStat As Long

    URL = (InternetGetConnectedState(WebStat, 0&) <> 0)
    
End Function

Could the error be due to the API? The code work son my 32 bit Excel so I assume the client has a 64 bit version? If so, how can I convert the API to make it work on both 32 bit and 64 bit Excel?

Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You need conditional compilation:

Code:
#If VBA7 then
Public Declare PtrSafe Function InternetGetConnectedState _
        Lib "wininet.dll" (lpdwFlags As LongPtr, _
        ByVal dwReserved As long) As Boolean
#Else
Public Declare Function InternetGetConnectedState _
        Lib "wininet.dll" (lpdwFlags As Long, _
        ByVal dwReserved As Long) As Boolean
#End If

Function URL() As Boolean
#If VBA7 then
    Dim WebStat As LongPtr
#Else
    Dim WebStat As Long
#End If

    URL = (InternetGetConnectedState(WebStat, 0&) <> 0)
    
End Function
 
Upvote 0
Solution
You need conditional compilation:

Code:
#If VBA7 then
Public Declare PtrSafe Function InternetGetConnectedState _
        Lib "wininet.dll" (lpdwFlags As LongPtr, _
        ByVal dwReserved As long) As Boolean
#Else
Public Declare Function InternetGetConnectedState _
        Lib "wininet.dll" (lpdwFlags As Long, _
        ByVal dwReserved As Long) As Boolean
#End If

Function URL() As Boolean
#If VBA7 then
    Dim WebStat As LongPtr
#Else
    Dim WebStat As Long
#End If

    URL = (InternetGetConnectedState(WebStat, 0&) <> 0)
   
End Function
Thanks, I'll add that in.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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