Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
kashjaniqlik
Contributor III
Contributor III

Storing txt in ansi format

Hello

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")

.Open

.Type = adTypeBinary

.LoadFromFile DestDir & UTF8FName

.Type = adTypeText

.Charset = "utf-8"

strText = .ReadText(adReadAll)

.Position = 0

.SetEOS

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

.WriteText strText, adWriteChar

.SaveToFile DestDir & ANSIFName, adSaveCreateOverWrite

.Close

End With



End sub

4 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

What happens if you try like this?

:

Set TextStream = CreateObject("ADODB.Stream")

With TextStream

     .Open

     :

Does it work?

Anil_Babu_Samineni

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

OR

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?

CreateObject("ADODB.Stream")



Please add me Anil_Babu_Samineni to interact faster when reply back. Speak low think High.

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)
kashjaniqlik
Contributor III
Contributor III
Author

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

Peter_Cammaert
Partner - Champion III
Partner - Champion III

In your script try with a dummy LOAD, like

TempTable:

LOAD FunctionName() AS DummyField AUTOGENERATE 1;

DROP Table TempTable;

Best,

Peter