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: 
souadouert
Specialist
Specialist

mid functon in macro

I used this script to export straight table with each selection date_s(yyyy/mm)

Si have to store each file qvd with this  ruls "straight"num_month .qvd

So i used this funtion NAMEFILE=Instr(String,6,2) to extract th month like MID() FUNTION

eg: 2017/10  title=10

set val=ActiveDocument.Fields("date_s").GetPossibleValues

for i=0 to val.Count-1

ActiveDocument.Fields("date_s").Select (val.Item(i).Text)

set obj = ActiveDocument.GetSheetObject("CH173")

set String=(val.Item(i).Text)

NAMEFILE=Instr(String,6,2)

    obj.ExportEx "C:\Users\04488\Desktop\Vision\straight"& NAMEFILE & ".qvd",4

next


but i have error Object required: '[string: "12/2015"]'

1 Solution

Accepted Solutions
tamilarasu
Champion
Champion

Yeah. Here is the correct code.

set val=ActiveDocument.Fields("date_s").GetPossibleValues

for i=0 to val.Count-1

      ActiveDocument.Fields("date_s").Select (val.Item(i).Text)

      set obj = ActiveDocument.GetSheetObject("CH173")

      NAMEFILE=  Right (val.Item(i).Text, 2)

     obj.ExportEx "C:\Users\04488\Desktop\Vision\straight"& NAMEFILE & ".qvd",4

next

View solution in original post

8 Replies
tamilarasu
Champion
Champion

Hi Souad,

Why not you use right function?

NAMEFILE = Right(val.Item(i).Text,2)

souadouert
Specialist
Specialist
Author

we cAn use with macro RIGHT()?


tamilarasu
Champion
Champion

Yeah. Here is the correct code.

set val=ActiveDocument.Fields("date_s").GetPossibleValues

for i=0 to val.Count-1

      ActiveDocument.Fields("date_s").Select (val.Item(i).Text)

      set obj = ActiveDocument.GetSheetObject("CH173")

      NAMEFILE=  Right (val.Item(i).Text, 2)

     obj.ExportEx "C:\Users\04488\Desktop\Vision\straight"& NAMEFILE & ".qvd",4

next

souadouert
Specialist
Specialist
Author

THANK YOU

m_woolf
Master II
Master II

You can use mid or right, but I'm guessing you will get an error with your filename. If val(item(i),Text contains "/". These are not valid symbols in file names. I usually use the replace function to replace "/" with "-".

tamilarasu
Champion
Champion

Hi M W,

You are right. But Souad is taking only the month numbers (01, 02... 12) from the date field. So I am pretty sure, it won't throw any error.

souadouert
Specialist
Specialist
Author

thank you for your interactivity

tamilarasu
Champion
Champion