Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
dhasharadh
Creator III
Creator III

Need help with macro to make selections and export it in txt format...??

Can any help me in writing the suitable macro with below requirements please. 

select BM01 (Bookmark) and previous month ( to select prev month - use select in field option - field/column name is WellMonth and the exp Date(addmonths(Today()-1),'YYYY-MM')

Export the straight table (CH02) in txt format. ( file name should be YYYYMMDD_File1.txt )  then

clear all selections in the dashboard

select BM02 (Bookmark) and previous month ( to select prev month - use select in field option - field/column name is WellMonth and the exp Date(addmonths(Today()-1),'YYYY-MM') then

Sub ExportButton
ActiveDocument.GetSheetObject("BU01").Press
End Sub
as we know the above macro will trigger a button. and above button contains 3 actions like - 1. clear all, 2. apply bookmark 3. run a macro.
3rd action run a macro should have to run the below macro which should make some selections in the dashboard and export the txt files with different names in the mentioned folder.
without adding the above small macro (trigger a button) below macro is working fine and generating the required files, but when we add both macros together we are not sure why but no files are generated. Please help us why this is happening....?
our expectation is - when we reload the app button should trigger and macro have to execute. tried post reload triggers as an alternate option but its not working either.
Sub export
curMonth = Month( DateAdd("M",-1, Date))
if curMonth<10 then curMonthS="0" & CStr(curMonth) else curMonthS=CStr(curMonth)
IF curMonth=1 OR curMonth=3 OR curMonth=5 OR curMonth=7 OR curMonth=8 OR curMonth=10 OR curMonth=12 Then
noofdays=31
else noofdays=30
end if
Dim wellNames(2)
wellNames(0)="Eden US"
wellNames(1)="Bwang US"
Set fso = CreateObject("Scripting.FileSystemObject")
For i = 0 to 1
ActiveDocument.Fields("GASMONTH").Select Year(Date)&"-"&curMonthS
ActiveDocument.Fields("SP.LANGBEZ_SSO_SPEICHER").Select wellNames(i)

strFile="F:\Test\Sch_section_" & wellNames(i) & "_UGS_01_" & curMonthS & "_" & noofdays & "_" & curMonthS & "_" & Year(Date) & ".txt"
Set MyFile = fso.CreateTextFile(strFile)

set table = ActiveDocument.GetSheetObject( "TB02" )
for RowIter = 0 to table.GetRowCount-1
set cell = table.GetCell(RowIter,0)
MyFile.WriteLine(cell.Text)
next
MyFile.Close
Next
MsgBox "completed"
'set fso = CreateObject("Scripting.FileSystemObject")
'
'File.Writeline vContent
'File.Close
End Sub
 
Thanks Much in advance.

Export the straight table (CH04 )in txt format. ( file name should be YYYYMMDD_File2.txt )

@jagan @marcus_sommer @Miguel_Angel_Baeyens  @Brett_Bleess 

can any one of you please help me on this. writing a single macro will definately help me to achieve. 

Thanks Much in advance. 

 

Labels (3)
4 Replies
Brett_Bleess
Former Employee
Former Employee

I would discourage the use of macros, they should be a last resort when developing as the macro engine is a very old version, and it also forces a single-thread condition during calculations etc., which may have a significant performance impact upon the application too.  I will let the others add their two cents, but that is about as much as I can offer on this one, I would find another means of doing what you are doing, we are not really an export tool, that is not the strength of the product, that analysis is the key focus of the product, so I am not sure why things are being exported out to be used in other tools...  

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
dhasharadh
Creator III
Creator III
Author

Thanks Much Brett for your reply. 

yeah even we tried to suggest the client to avoid using the macro and opt for some third party tools like Nprinting,

But this is our only report with this kind of requirement so we cant afford Nprinting for this. 

So there is no other way apart from macros and using macros is not recommendable.  we are in confused state now !! 🤔

marcus_sommer

With the help of the APIGuide.qvw (within your QV install folder by automation) it should not be too difficult to develop such macro. There are various examples related to bookmarks (just search within the listboxes "Class" and "Member" for "*book*" and you will find many attributes and examples to them and also to other measures.

Of course you will need some trial & error to develop it step by step (some simplified dummy-app may be useful to learn how it worked instead of trying it within the final app) and by identifying the key-words for your tasks you could use them to search for them within the community (maybe someone else did something very similar and you could copy & paste from there some logic to speed up your task).

- Marcus

dhasharadh
Creator III
Creator III
Author

Hi Marcus , 

Thanks for your reply,

please look into macro in the main thread . we almost achieved it, but facing difficulty in having the multiple macros. please help us. Thanks in advance.