Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcing the newest addition to the Qlik Community, Qlik Gallery! Learn More
New Contributor III

Storing txt in ansi format


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


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

4 Replies

Re: Storing txt in ansi format

What happens if you try like this?


Set TextStream = CreateObject("ADODB.Stream")

With TextStream



Does it work?


Re: Storing txt in ansi format

Where do you run this, May be you have to allow system access to macro.


You may need to create as variable

Syntax should be something like CreateObject(Excel.Application);

From below, Excel fiele name is ADODB and application called Stream. Is that information is correct?


Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
New Contributor III

Re: Storing txt in ansi format

Thanks all for your response.

I have managed to find the issue.  The macro didn't had the right module and local security.

I can call this macro through a button although it fails through the load script. I get Script line error.

I'm using Call FunctionName()

Any Ideas?

Thanks once again

Re: Storing txt in ansi format

In your script try with a dummy LOAD, like


LOAD FunctionName() AS DummyField AUTOGENERATE 1;

DROP Table TempTable;