Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Check out our latest virtual session where BARC Fellow, Doug Laney, highlighted the opportunities data monetization can offer enterprises. Watch here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Can I set ActiveObject in Macro?

Hello,

I'm wondering if it is possible to make the macro below a bit more dynamic.

It is the part that goes

Set chart = ActiveDocument.GetSheetObject("CH72")

that I want to change into selecting the object that is active instead.

Is there anyone who knows if this is possible?

Sub SaveFile

Dim outputFile, oFSO, oFile, line

'Get filename for saving

outputFile = GetFileSaveDlg()

'Create necessary objects

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFile = oFSO.CreateTextFile(outputFile)

Set chart = ActiveDocument.GetSheetObject("CH72")

'Loop through rows and columns of chart

   For row = 0 to chart.GetRowCount-1

    line = ""

    For col = 0 to chart.GetColumnCount-1

     If (Len(line) > 0) Then

      line = line & VbTab

     End If

     'Get cell value and append to line

     Set cell = chart.GetCell(row, col)

     line = line & cell.Text

    Next

    'Write line to file

    oFile.WriteLine line

   Next

   oFile.Close

End Sub

br

Martin

1 Reply
erichshiino
Partner - Master
Partner - Master

Hi,

There might be more than one active object.

... but you can loop all of them and apply your macro to all the active ones.

The following code will let you loop all the objects in the active sheet and check which ones are active

r

set s=ActiveDocument.ActiveSheet

objs=s.GetSheetObjects

for i=lbound(objs) to ubound(objs)

    if objs(i).IsActive then objs(i).Minimize

' Instead of minimize, you could start your code

next

Hope this helps,

Erich