Base64 decode

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,092
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I have a need to extract text attachments from incoming mail in Thunderbird. It won't do this as a batch operation. I made a VBA routine which takes the Base64 encoded section and passes it to
VBA Code:
Function DecodeBase64(b64$)
    Dim b
    With CreateObject("Microsoft.XMLDOM").createElement("b64")
        .DataType = "bin.base64": .Text = b64
        b = .nodeTypedValue
        With CreateObject("ADODB.Stream")
            .Open: .Type = 1: .Write b: .Position = 0: .Type = 2: .Charset = "utf-8"
            DecodeBase64 = .ReadText
            .Close
        End With
    End With
End Function
But about 1 in 10 fail with error -2147024809. "The Parameter is incorrect".
However if I load the pattern into Base64 Decode and Encode - Online it decodes correctly. The pattern is:

NjM0QF4xOTQ2XkBeQmlsbGJvYXJkXkBeU000Nl8wMjBeQF5TTTQ2XzAxOF5AXjIxXkBeOV5A
XjEyXkBeMV5AXjJeQEBeVW5kZXIgVGhlIFdpbGxvdyBUcmVlXkBAXkJpbGx5IFJlaWReQEBA
QEBeXkBAQEBAXk1hY21lbG9kaWVzIEx0ZF5AMiwxMSwxOTQ1IDA6MDA6MDBANCwxLDE5NDYg
MDowMDowMEAyMiwzLDE5NDYgMDowMDowMEBeMTMsMTYsMTUsMTEsNyw1LDUsNSw1LDIsNCwz
LDUsNiw1LDgsMTEsMTIsMTQsMTQsMjBeQF4xNl5AXjE1XkBeMTFeQF43XkBeNV5AXjVeQF41
XkBeNV5AXjJeQF40XkBeM15AXjVeQF42XkBeNV5AXjheQF4xMV5AXjEyXkBeMTReQF4xNF5A
XjIwXkBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA
QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA
QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBeMTNeQDBAQEBAQF4xM15AQEBeM15AQEBeYSkg
RG9yb3RoeSBTcXVpcmVzICAoUGFybG9waG9uZaBGIDIxMDEpCmIpIEhhcnJ5IFJveSAgKFBh
cmxvcGhvbmWgRiAyMTA3KQpjKSBCaWxseSBDb3R0b24gIChSZXggMTAyMjkpXkBANjM2QDIw
QF5TaGVldE11c2ljXkBeMF5AXjBeQF4wXkBeMF5AMQ0K

Does anyone know what the problem might be ?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I got that error when I did not pass the parameter value to the .ReadText ie .ReadText 10000. The value can be greater than expected and it just returns what is left.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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