Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I need to use three similar (but different) macros within my QVW. In each macro only the highlighted portion would differ. The challenge I face is, if I modify the code in one place, the same modification gets reflected across the QVW in all other macro codes. How to modify the below code without affecting a similar code elsewhere in the QVW. FYI: I am calling these macros within a Button action.
Thanks,
Sudha.
You need to have three different Subs ... this is the "quickest" and "dirtyest" way of doing it:
Sub ExportExcel_1
Set obj = ActiveDocument.GetSheetObject("CH33")
obj.ExportBiff "c:\temp\yyyy1.xls"
Set v=ActiveDocument.Variables("vShowColumn")
v.SetContent "0",true
End Sub
Sub ExportExcel_2
Set obj = ActiveDocument.GetSheetObject("CH34")
obj.ExportBiff "c:\temp\yyyy2.xls"
Set v=ActiveDocument.Variables("vShowColumn")
v.SetContent "0",true
End Sub
Sub ExportExcel_3
Set obj = ActiveDocument.GetSheetObject("CH35")
obj.ExportBiff "c:\temp\yyyy3.xls"
Set v=ActiveDocument.Variables("vShowColumn")
v.SetContent "0",true
End Sub
Then use different Subs for each Button....
I don't understand the problem. If you have different subroutines like you say then you can modify each subroutine without affecting the others.
I have the button with the macro code in QVW as shown:
I have the similar logic within button in three places within the same qlikview document.
If I change the Chart number and/or the target file location, the change gets reflected within all the buttons (macro code) in the document. Hope you get the issue.
So you're using the same subroutine for all the buttons. If you don't want that the create more subroutines and assign the different subroutines to the different buttons.
You need to have three different Subs ... this is the "quickest" and "dirtyest" way of doing it:
Sub ExportExcel_1
Set obj = ActiveDocument.GetSheetObject("CH33")
obj.ExportBiff "c:\temp\yyyy1.xls"
Set v=ActiveDocument.Variables("vShowColumn")
v.SetContent "0",true
End Sub
Sub ExportExcel_2
Set obj = ActiveDocument.GetSheetObject("CH34")
obj.ExportBiff "c:\temp\yyyy2.xls"
Set v=ActiveDocument.Variables("vShowColumn")
v.SetContent "0",true
End Sub
Sub ExportExcel_3
Set obj = ActiveDocument.GetSheetObject("CH35")
obj.ExportBiff "c:\temp\yyyy3.xls"
Set v=ActiveDocument.Variables("vShowColumn")
v.SetContent "0",true
End Sub
Then use different Subs for each Button....
I tried this. But even changing the sub reflects everywhere. So, if I change the sub name from 'ExportExcel' to 'Hello', it again gets reflected everywhere. The moment I try to create a new macro code within a button, by default, I get the existing code and modifying that in anyway gets reflected everywhere.
You could create two variables in QV (ex: vParam1 and vParam2), one per each value that changes in the macro.
Then, whithin every button's actions, set those variables with the desired values and call the macro.
The macro changed for the mentioned example:
sub ExportExcel
'set the macro variables with qv variables value
set pseudoParam1 = ActiveDocument.Variables("vParam1")
set pseudoParam2 = ActiveDocument.Variables("vParam2")
set obj = ActiveDocument.GetSheetObject(pseudoParam1 )
obj.ExportBiff pseudoParam2
....
Hope this helps.
Regards,
Thanks for your suggestion. Unfortunately, I am very new to macro coding. Could you please help me with my existing code...how do I introduce new variables here. I should be able to retain my existing variable vShowColumn
Something like this,
Let me know if it works.
Regards,
It's Awesome. Thank you! I am trying to implement this but I am getting the below error.