String VBA-从GUID中删除括号{}
您好,我刚刚实施了新的修复程序,用于在microsoft更新后生成GUID代码。我是VBA新手,你能帮我从下面的代码中删除用GUID生成的{}花括号吗String VBA-从GUID中删除括号{},string,vba,guid,String,Vba,Guid,您好,我刚刚实施了新的修复程序,用于在microsoft更新后生成GUID代码。我是VBA新手,你能帮我从下面的代码中删除用GUID生成的{}花括号吗 Private Type GUID_TYPE Data1 As Long Data2 As Integer Data3 As Integer Data4(7) As Byte End Type Private Declare PtrSafe Func
Private Type GUID_TYPE
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Declare PtrSafe Function CoCreateGuid Lib "ole32.dll" (guid As GUID_TYPE) As LongPtr
Private Declare PtrSafe Function StringFromGUID2 Lib "ole32.dll" (guid As GUID_TYPE, ByVal lpStrGuid As LongPtr, ByVal cbMax As Long) As LongPtr
Public Function GetGUID()
Dim guid As GUID_TYPE
Dim strGuid As String
Dim retValue As LongPtr
Const guidLength As Long = 39 'registry GUID format with null terminator {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
retValue = CoCreateGuid(guid)
If retValue = 0 Then
strGuid = String$(guidLength, vbNullChar)
retValue = StringFromGUID2(guid, StrPtr(strGuid), guidLength)
If retValue = guidLength Then
GetGUID = strGuid
End If
End If
结束函数编辑了这一行
GetGUID=Replace(Replace(strGuid,“{,”),“},”)只需使用
Mid
删除第一个和最后一个字符。
您还可以使用字节数组来保存guid和结果字符串
要生成GUID,请执行以下操作:
Private Declare PtrSafe Function CoCreateGuid Lib "ole32.dll" (pguid As Byte) As Long
Private Declare PtrSafe Function StringFromGUID2 Lib "ole32.dll" (rguid As Byte, lpsz As Byte, ByVal cchMax As Long) As Long
Public Function GenerateGUID() As String
Dim pguid(0 To 15) As Byte, lpsz(0 To 77) As Byte
CoCreateGuid pguid(0)
StringFromGUID2 pguid(0), lpsz(0), 39
GenerateGUID = Mid$(lpsz, 2, 36)
End Function
例如:guid='{abcd}';然后使用“new_guid=Replace(Replace(guid),{,,,},”)