4 Replies Latest reply: Feb 3, 2017 12:37 PM by Peter Cammaert RSS

    Storing txt in ansi format

    Kash Jani



      I'm trying to execute below macro through a button in Qlikview and doing a test through Module editor, it complains about

      With CreateObject("ADODB.Stream")


      Am I missing something on machine (dll etc) that can allow me to use the above object?




      Public Sub ConvertInterFaceFileUTF8toANSI()

      Dim StrText

      Dim adReadAll

      Dim adSaveCreateOverWrite

      Dim adTypeBinary

      Dim adTypeText

      Dim adWriteChar

      Dim DestDir

      Dim UTF8FName

      Dim ANSIFName

      DestDir = ActiveDocument.GetVariable("vInterfaceFileDirectory").getcontent.string

      UTF8FName = ActiveDocument.GetVariable("vInterFaceUTF8FileName").getcontent.string

      ANSIFName = ActiveDocument.GetVariable("vInterfaceFileName").getcontent.string

      adReadAll = -1

      adSaveCreateOverWrite = 2

      adTypeBinary = 1

      adTypeText = 2

      adWriteChar = 0

      With CreateObject("ADODB.Stream")


      .Type = adTypeBinary

      .LoadFromFile DestDir & UTF8FName

      .Type = adTypeText

      .Charset = "utf-8"

      strText = .ReadText(adReadAll)

      .Position = 0


      .Charset = "_autodetect" 'Use current ANSI codepage.

      .WriteText strText, adWriteChar

      .SaveToFile DestDir & ANSIFName, adSaveCreateOverWrite


      End With

      End sub