VBA Compile error

biggsy3

New Member
Joined
Jan 27, 2014
Messages
42
Hello All,
My VBA experience is very limited, but hoping someone can help me with the following;
Since a systems update at work, were they replaced all our desktops, I've been getting an error when opening an Excel report. Please find attached screenshot of the compile error. This is where my knowledge is very limited, in my VBA code there is a declare statement that needs updating because my system is now 64bit. I have found the statement but I have no idea how I can make it work.

This is the issue:

Rich (BB code):
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long

Here is the full code:
Rich (BB code):
Option Explicit
'Option Private Module
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long

Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
                                                                                                                                             
Private Sub Guidtest()
 Debug.Print GetGUID
End Sub
                                                                                                                                              

Public Function GetGUID() As String
'(c) 2000 Gus Molina
Dim udtGUID As GUID
Dim Temp As String
Dim Ret As String
If (CoCreateGuid(udtGUID) = 0) Then
Temp = _
String(8 - Len(Hex$(udtGUID.Data1)), "0") & Hex$(udtGUID.Data1) & _
String(4 - Len(Hex$(udtGUID.Data2)), "0") & Hex$(udtGUID.Data2) & _
String(4 - Len(Hex$(udtGUID.Data3)), "0") & Hex$(udtGUID.Data3) & _
IIf((udtGUID.Data4(0) < &H10), "0", "") & Hex$(udtGUID.Data4(0)) & _
IIf((udtGUID.Data4(1) < &H10), "0", "") & Hex$(udtGUID.Data4(1)) & _
IIf((udtGUID.Data4(2) < &H10), "0", "") & Hex$(udtGUID.Data4(2)) & _
IIf((udtGUID.Data4(3) < &H10), "0", "") & Hex$(udtGUID.Data4(3)) & _
IIf((udtGUID.Data4(4) < &H10), "0", "") & Hex$(udtGUID.Data4(4)) & _
IIf((udtGUID.Data4(5) < &H10), "0", "") & Hex$(udtGUID.Data4(5)) & _
IIf((udtGUID.Data4(6) < &H10), "0", "") & Hex$(udtGUID.Data4(6)) & _
IIf((udtGUID.Data4(7) < &H10), "0", "") & Hex$(udtGUID.Data4(7))
Ret = Left(Temp, 8) & "-"
Ret = Ret & Mid(Temp, 9, 4) & "-"
Ret = Ret & Mid(Temp, 13, 4) & "-"
Ret = Ret & Mid(Temp, 17, 4) & "-"
Ret = Ret & Mid(Temp, 21)
Ret = "{" & Ret & "}"
GetGUID = Ret
End If
End Function

I would be very grateful if anyone could help me with this.

Regards,
 

Attachments

  • Error.PNG
    Error.PNG
    6 KB · Views: 14
Last edited by a moderator:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Change this line:

Code:
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long

to this:

Code:
#IF VBA7 then
Private Declare PtrSafe Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long
#Else
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long
#End If
 
Upvote 0
Change this line:

Code:
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long

to this:

Code:
#IF VBA7 then
Private Declare PtrSafe Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long
#Else
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long
#End If

That was quick, seems to have worked. Thank you for saving the day RoryA!

Just to check the following line still shows in red is this correct?
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long
 
Upvote 0
Yes, that's fine. It won't be run on anything after Excel 2007, but the compiler will still flag it in red.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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