Base64Decode UTF8

gebarbour

New Member
Joined
Nov 8, 2022
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
I am running a function similar to the one offered by AlexanderBB that follows but it runs very slow when the Base64 string gets large at the point where ADODB.Stream .ReadText is set as the function return.

Function DecodeBase64(b64$)
Dim b
With CreateObject("Microsoft.XMLDOM").createElement("b64")
.DataType = "bin.base64": .Text = b64
b = .nodeTypedValue
End With

With CreateObject("ADODB.Stream")
.Open: .Type = 1: .Write b: .Position = 0: .Type = 2: .Charset = "utf-8"
DecodeBase64 = .ReadText
.Close
End With

End Function

I have read that this can happen when the ADODB.Stream gets large and a work around can be to process the stream using a line loop something similar to the following where -2 denotes the line

do while o.EOF --o is the adoStream
s = s & o.ReadText -2 --s is a string return
loop
DecodeBase64 = s

Now this does not work in the following code because of the binary flow, so I wondered if anyone had any idea how I could refactor the code to process the stream into smaller chunks so that the ADODB.Stream does not flip out with large volume of data. Please note that the UTF8 part is important hence the use of the ADODB.Stream in the first place.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,215,126
Messages
6,123,198
Members
449,090
Latest member
bes000

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