I need to create a Base64 String which relates to a PDF file that I have. I have tried the below, but the output (EncodeFileBase64) that is generated isn't working - I think the output being produced is being truncated, because when I put the output into a decoder tool, it knows it's a PDF but produces an error when I try to open it.
Attached are 2 documents, 1 showing what the below code is currently producing when being input into an excel cell, and the other document is showing what the Base64 String should look like (which is a lot longer!)
Public Sub File_for_Converting()
FileName = "C:\Geographic Regional Sales Analysis.pdf"
Call Main.EncodeFileBase64(FileName)
End SubFunction EncodeFileBase64(FileName As String) As String
Dim arrData() As Byte
Dim fileNum As Integer
fileNum = FreeFile
Open FileName For Binary As fileNum
ReDim arrData(LOF(fileNum) - 1)
Get fileNum, , arrData
Close fileNum
Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
Set objXML = New MSXML2.DOMDocument
Set objNode = objXML.createElement("b64")
objNode.DataType = "bin.base64"
objNode.nodeTypedValue = arrData
EncodeFileBase64 = objNode.Text
Range("B8").Value = EncodeFileBase64
Set objNode = Nothing
Set objXML = Nothing
End Function
Bookmarks