Word VBA Replace multiple Spaces in Text with BB Code String

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word VBA Replace multiple Spaces in Text with BB Code String

Post by HansV »

> Does not work, or does not work very well?
Does not work at all. Microsoft simply hasn't exposed a class name for DataObject, unlike for example Scripting.FileSystemObject or WScript.Shell.
Most object we use do have a class name. For those we can use early binding by setting a reference, or late binding by using GetObject/CreateObject with a class name.
DataObject is an exception, so we MUST use its hexadecimal ClassID.
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: Word VBA Replace multiple Spaces in Text with BB Code String

Post by SpeakEasy »

>why I have never needed to employ 36-character strings before;

It's the formal string representation of the underlying 128bit UUID (which Microsoft tend to refer to as a GUID; a CLSID is just a GUID being used for a specific role - identifying a class object), that representation being 32 hexadecimal digits separated by 4 hyphens ...

We humans are sheltered from them normally, but there are odd occasions where we find we have to use them. Not very often for most users, it has to be said.

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

CLSIDs in the { } as in CreateObject("New:" & “{aksjjfhaskj}” & "")

Post by Doc.AElstein »

Hi,
Sorry it’s a bit off topic, but as we all touched on the subject, I thought just out of interest , and for future reference… …… after I gave up looking for how to programmatically get a list of all those CLSID things, I found some stuff by accident and did it!! ( I must remember to give up wasting time looking for things, - it’s very inefficient as I rarely find stuff, - I find things quite efficiently when I am not looking for them.)

I can get a full list very quickly - Sub ListCLSIDs() in the uploaded file does that.
In the uploaded file in column A you can see that I have about 6500 CLSIDs on the computer I initially tested it on.

Getting the names using the idea I had does not work so well. My idea was of a macro using error handling and trying something like pseudo like Set OOPObj = CreateObject("New:" & {The CLSID String} & "") followed by TypeName(OOPObj)
I wrote a macro to do that, but it keeps opening all sorts of applications, doing other strange things and crashing. I guess it’s not very sensible trying to create every object possible.
Never mind, - I wrote that macro, Sub CLSIDsValueNames() , to run on a selection of the CSIDs in column A. So you can do a few rows at a time , and build the list up that way. It is a very slow inefficient macro as it saves every time it loops so that you don’t loose too much information when it crashes.
I have not got around to completing the list, but what I will do whenever I have the time is build up that list and a few more, and re upload the file to the file sharing place. So as time goes on that file will get more and more info in it. the share link will stay the same. As time goes on I will add a sheet for different computers, as I expect the CLSID lists will be a bit different on different computers.
I expect as time goes on I will get to see what things cause a crash, and probably add a few notes in the file.

( If anyone out of interest wants to add a sheet on my file of their results then let me know and I will add it to the main file I keep at the link ).

Might be academically interesting to compare list on different computers

File: CLSDsUndClassNames.xls https://app.box.com/s/gx5zfvnnjkqoakalj81h7thdme1cib1d


Alan

Code: Select all

 ' ' https://powershell.one/wmi/root/cimv2/stdregprov-EnumKey    '   https://www.vbforums.com/showthread.php?552899-Getting-all-sub-keys-from-a-registry-value                  https://www.vba-tutorial.de/apireferenz/registry.htm
Sub ListCLSIDs() '  http://www.eileenslounge.com/viewtopic.php?f=26&t=22603&p=289007#p289007
Dim Ws As Worksheet: Set Ws = ActiveSheet
Dim Registry As Object, varKey As Variant, varKeys As Variant
 Set Registry = GetObject("winmgmts:\\.\root\default:StdRegProv")
 Registry.EnumKey 2147483650#, "SOFTWARE\Classes\CLSID", varKeys ' https://powershell.one/wmi/root/cimv2/stdregprov-EnumKey
    For Each varKey In varKeys
    Let Ws.Range("A" & Ws.Range("A" & Ws.Rows.Count & "").End(xlUp).Row + 1 & "").Value = varKey
    Next
End Sub

Code: Select all

Sub CLSIDsValueNames()
Dim Ws As Worksheet: Set Ws = ActiveSheet
Dim RngSel As Range: Set RngSel = Selection
    If RngSel.Cells.Count = 1 Then MsgBox prompt:="Please select at least 2 cells in column A": Exit Sub
    If RngSel.Cells.Columns.Count <> 1 Then MsgBox prompt:="Please select at least 2 cells in only column A": Exit Sub
    If Not RngSel.Cells.Column = 1 Then MsgBox prompt:="Please select at least 2 cells in column A": Exit Sub
Dim stearCel As Range
    For Each stearCel In RngSel
     Let Ws.Range("B" & stearCel.Row & "").Value = "Tried" ' To indicate I tried - this can be useful to see where it crashed
    Dim OOPObj  As Object
    On Error GoTo EyeEyeSkipper
     Set OOPObj = CreateObject("New:" & stearCel.Value & "")
     Let Ws.Range("D" & stearCel.Row & "").Value = TypeName(OOPObj)
     Let Application.DisplayAlerts = False
     ThisWorkbook.Save ' This is done to save all got so far incase Excel crashes on next loop or below
     Let Application.DisplayAlerts = True
    On Error Resume Next
    OOPObj.Close
    On Error GoTo 0
    Set OOPObj = Nothing
EyeEyeSkipper:
    On Error GoTo -1
    On Error GoTo 0
    Next stearCel
End Sub
_._______________________________________

P.S. The name is not always that revealing as it could be, In our example, the key of "{1C3B4210-F441-11CE-B9EA-00AA006B1A69}" gives the name of IDataAutoWrapper
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word VBA Replace multiple Spaces in Text with BB Code String

Post by ChrisGreaves »

SpeakEasy wrote:
21 Oct 2021, 16:55
>why I have never needed to employ 36-character strings before;
@Hans & @Speakeasy: Thank you. It appears that I have led a sheltered life to date!
Cheers
Chris
An expensive day out: Wallet and Grimace