• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Creating RQUIDs|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Creating RQUIDs|VBA & Macros|Excel Forum|My Online Training Hub

vba course banner

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosCreating RQUIDs
sp_PrintTopic sp_TopicIcon
Creating RQUIDs
Avatar
Blanka Blair
Member
Members
Level 0
Forum Posts: 53
Member Since:
October 17, 2015
sp_UserOfflineSmall Offline
1
March 2, 2018 - 1:17 am
sp_Permalink sp_Print

I need help badly, I'm a beginner when it comes to VBA.

I have to create hundreds of RQUIDs almost daily. I have a macro (created by someone else) which worked beautifully until yesterday, when we had Excel updated. Now I'm getting Error '70' when my macro gets to the CreateObject line.

I searched Microsoft's website on how to work around the issue and they do show an example, but I have no idea how to incorporate it into my macro.

My original Macro:

-----------------------------------------

Sub GenerateGuids()
    Dim iGuids As Integer
    Dim iRow As Integer
   
    iGuids = InputBox("How Many Guids Do You Want?", "Guid Generator")
    If iGuids <= 100000000 Then
        iRow = 2
       
        Do While iRow <= iGuids
            Application.ActiveSheet.Cells(iRow, 1) = GenGuid()
            iRow = iRow + 1
        Loop
       
    ElseIf iGuids < 1 Then
        MsgBox ("You must generate at least 1.")
    Else
        MsgBox ("That is a lot of guids, the maximum I can generate is 100 million, and that's probably going to error before I am done.")
       
    End If
End Sub

Function GenGuid() As String
    Dim TypeLib As Object
    Dim guid As String
    Set TypeLib = CreateObject("Scriptlet.TypeLib")
    guid = TypeLib.guid
   
    guid = Replace(guid, "{", "")
    guid = Replace(guid, "}", "")
    'Guid = Replace(Guid, "-", "")
    GenGuid = guid
End Function

-----------------------------------------

This is what Microsoft says:

Workaround

The preferred method is to change the code to use Windows API CoCreateGuid instead of “CreateObject(“Scriptlet.TypeLib”).Guid”

Example of CreateObject error '70':

Dim strGuid As String

StrGuid = Left$(CreateObject("Scriptlet.TypeLib").Guid, 38)

 

Example of CoCreateGuid(…): Vba7 Win64 Office 64-bit

‘ No VT_GUID available so must declare type GUID

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

Function CreateGuidString()

                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

                                                ‘ valid GUID as a string

CreateGuidString = strGuid

                                End If

                End if

End Function

------------------------------

I would be very grateful if someone could combine these two macros into a workable one.

Thank you,

Blanka

sp_AnswersTopicSeeAnswer See Answer
Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
2
March 2, 2018 - 1:09 pm
sp_Permalink sp_Print

Hi Blanka

Not tested on a 64 bit Excel but should work. I have limited the number of GUID generation to 500,000 (Excel maximum rows is around 1 million only).

Change to suit your needs.

Hope this helps.

Sunny

sp_AnswersTopicAnswer
Answers Post
Avatar
Blanka Blair
Member
Members
Level 0
Forum Posts: 53
Member Since:
October 17, 2015
sp_UserOfflineSmall Offline
3
March 3, 2018 - 12:53 am
sp_Permalink sp_Print

Hi Sunny,

It works perfectly. You are awesome! You saved me hours of frustration.

Thank you, thank you, thank you. I can't thank you enough.

Blanka

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
4
March 3, 2018 - 9:22 am
sp_Permalink sp_Print

Hi Blanka

Thanks for your generous feedback Laugh

Glad to know it is working for you.

Cheers

Sunny

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: ash seth, Jessica Stewart, Franziska Reinbold, Patrick Gillan
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 216
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
leandro barbarini
Melanie Ford
Isaac Felbah
Adele Glover
Hitesh Asrani
Rohan Abraham
Anthony van Riessen
Erlinda Eloriaga
Abisola Ogundele
MARTYN STERRY
Forum Stats:
Groups: 3
Forums: 24
Topics: 6356
Posts: 27793

 

Member Stats:
Guest Posters: 49
Members: 32325
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.