Showing posts with label Utils. Show all posts
Showing posts with label Utils. Show all posts

Monday, October 11, 2010

Bye bye NAVIGATION TABS

After a little vacation, let´s get to work.

I don´t know why, but I don´t like using the navigation tab buttons on my reports. Probably it is because I have to set lots of properties and create the same objects (filters, logo, report name, etc) for each of the tabs.

A couple of months ago I started using  object´s conditional show to create a tab that would have all my objects. When pressing a "Dashboard" button, the dashboard objects would appear. When pressing a "Regional" button, only the regional objects would appear.

The biggest problem with this approach is that I needed to set individually the condition that would make the objects appear or not.

To make my job easier, I have come with the macro below so that I can write my condition, choose the objects I want and then set for all of them the same condition making the development and maintenance easier. It is almost a group condition.
 
WHAT
 I have took the macro below and changed it a little to allow setting a "conditional show" for multiple objects.

HOW
You cannot use a button to call the macro. If you do, when pressing the buttons the objects you have selected to apply the macro will be deselected and the macro will be applied over the button. We need to make a little workaround when using the macro.

1. first create 2 vars: vLayout and vShowCondText.

2. copy the code to the Macro Module:

sub setShowCondition
' vars
set doc = ActiveDocument


' grab the text to be used as the condition
condText = ActiveDocument.Variables("vShowCondText").GetContent.String
' msgBox(condtext)


' traverse the selected objects setting the new condition text
set s=doc.ActiveSheet
objs=s.GetActiveSheetObjects
for i=lbound(objs) to ubound(objs)

 ' get the object's name and property
   set objInt = objs(i)
   objID = replace(objInt.GetObjectId,"Document\","")
   set obj = doc.GetSheetObject(objID)
   objProp = obj.GetProperties
 
   ' as each object has diferent places for the frame object, treat them differently
   select Case objs(i).GetObjectType
     Case 1,2,3,4,6,7,8,9,17,18,19,34,35 'LB,MB,SB,TB,TX,CS,IB,LA
     objProp.Layout.Frame.Show.Always = false
     objProp.Layout.Frame.Show.Expression.v = condText

     Case 5,31 'BU,SO
     objProp.Frame.Show.Always = false
     objProp.Frame.Show.Expression.v = condText
   
     Case 10,11,12,13,14,15,16,20,21,22,27,28 'CH's
     objProp.GraphLayout.Frame.Show.Always = false
     objProp.GraphLayout.Frame.Show.Expression.v = condText
     Case Else
      msgbox("ObjectID: " &objID & " with objectType: " & objs(i).GetObjectType &" couldn't be found, trying LB settings")
      objProp.Layout.Frame.Show.Always = false
      objProp.Layout.Frame.Show.Expression.v = condText
     end select
   obj.SetProperties objProp
  next
end sub


 USING THE MACRO
    1. Create the button.

    2. Configure it to set the value to the vLayout variable.


    3. Write the condition you want. I have created an input object that will set automatically the value to the var vShowCondText.

    4. Select the objects you want to set the condition.

    5. Now, the workaround part. Open the Module Screen (CTRL+M). Select the function setShowCondition on the left side.



    6. Below the function list, click the TEST button . It will execute the macro chosen before.


    That´s it. When pressing the new button, the objects will appear. You may want to create a logic to set/unset the vLayout variable so that the same button enables/disables the objects, or create another button that will set another value to vLayout, making the objects with the value PRINCIPAL to disappear appearing the new ones.

    Hope it helps. Please comment.

    Wednesday, September 15, 2010

    You have the right to remain still!!

    All the credits go for Guerrila BI. Nice macro he did. Check the original post at http://guerrillabi.com/node/26

    Before publishing a Report it is good to make all the objects static. This is specially true with the version 9 that the user is allowed to create his own objects and move the original ones.

    I was making my little precious this morning when I bumped into the post above. The first thing I though was F#$. I had spent a couple of ours in the making to discover that the work was already done.

    Anyway, below goes the code with a little adaptation:

    What

    Create a set of button that will enable/disable the move operation for all objects. Perfect for report design then publish.

    How

    At the edit module (CTRL+M) paste the code below. It will basically traverse all sheets and all objects to enable/disable move. The commented code is the original code that I did not use. Maybe you will.



    ' Enable the move resize for all objects on the report.
    sub EnableMove

    ' do the magic
    setMove TRUE,TRUE
    end sub


    ' Disable the move resize for all objects on the report.
    sub DisableMove

    ' do the magic
    setMove FALSE,FALSE
    end sub




    ' Set the move properties to all objects
    'msVal - Move/Size setting for non-chart objects
    'chVal - Copy/Clone setting for non-chart objects
    'amVal - Auto Minimize setting for chart objects
    'ccVal - Move/Size setting for chart objects
    function setMove (msVal, ccVal)
    set doc = ActiveDocument


    ' for all the sheets set the property chosen 
    for j = 0 to ActiveDocument.NoOfSheets - 1
    set s=ActiveDocument.GetSheet(j)
    objs=s.GetSheetObjects

    ' for all objects
    for i=lbound(objs) to ubound(objs)

    ' get the object's name and property
    set objInt = objs(i)
    objID = replace(objInt.GetObjectId,"Document\","")
    'msgbox("obj ID " & objID &" has the objType " & objs(i).GetObjectType)
    set obj = doc.GetSheetObject(objID)
    objProp = obj.GetProperties

    ' as each object has diferent places for the frame object, treat them differently
    select Case objs(i).GetObjectType
    Case 1,2,3,4,6,7,8,9,17,18,19,34,35 'LB,MB,SB,TB,TX,CS,IB,LA
    objProp.Layout.Frame.AllowMoveSize = msVal
    'objProp.Layout.Frame.AllowCopyClone = ccVal 
    Case 5,31 'BU,SO
    objProp.Frame.AllowMoveSize = msVal
    Case 10,11,12,13,14,15,16,20,21,22,27,28 'CH's
    objProp.GraphLayout.Frame.AllowMoveSize = msVal
    'objProp.GraphLayout.Frame.AllowCopyClone = ccVal
    'objProp.GraphLayout.Frame.AutoMinimize = amVal
    Case Else
    msgbox("ObjectID: " &objID & " with objectType: " & objs(i).GetObjectType &" couldn't be found, trying LB settings")
    objProp.Layout.Frame.AllowMoveSize = msVal
    'objProp.Layout.Frame.AllowCopyClone = ccVal
    end select
    obj.SetProperties objProp
    next
    next
    end function


    Now create the buttons and call the subs EnableMove and DisableMove. Good thing to let them hidden before publishing.

    And VIVA LA REVOLUCIÓN!!!