Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
thomas_skariah
Creator III
Creator III

Help in Macro

Hi All,

I have a qlikview application which export certain charts (not image)  to excel in different sheets through button (i.e creating a new excel sheet to a specified location), now i have put a macro inside the stored excel file and execute the macro from qlikview.

Can anyone suggest how to put the macro inside the excel file exported from Qlikview and how to run that macro from qlikview.

or how to export those charts to an existing excel file (In which it will delete the previous sheet or value and create the new sheets ) where the macro is already stored.

Thanks.

Regards,

Tom

4 Replies
Not applicable

Not quite sure I follow, however you have the external macro in a batch script, then call that from an Action command within QV - ie. Add Action/External/Open URL (URL to the batch script).


Not applicable

Hi Tony,

write your excel macro code inside a sheet event OnOpen.So it will execute if any one opens that excel file.

Now from qlikview side we can make it open,save and close automatically using vbscript/macro through any trigger.

Please try this,

Sub ExecuteExcel

Dim objXLApp, objXLWb, objXLWs

Set objXLApp = CreateObject("Excel.Application")
Set objXLWb = objXLApp.Workbooks.Open("E:\Docs\Invoice.csv")

objXLWb.Save
objXLWb.Close (False)

Set objXLWs = Nothing  
Set objXLWb = Nothing

objXLApp.Quit
Set objXLApp = Nothing

End Sub

Regards

Kumar

thomas_skariah
Creator III
Creator III
Author

Hi Ravi,

Thanks for your comment.

Can you give the steps for sheet event OnOpen.

Regards,

Tom

Not applicable

Hi,

Please look at this example.

Another way to automatically run a macro when you open a workbook is to write a VBA procedure in the Open event of the workbook by using the Visual Basic Editor. The Open event is a built-in workbook event that runs its macro code each time you open the workbook.

The following simple example uses the Open event to run a macro when you open the workbook.

  1. Save and close all open workbooks.
  2. Open the workbook you want add the macro to, or create a new workbook.
  3. On the Tools menu, point to Macro, and then click Visual Basic Editor.
  4. In the Project Explorer window, right-click the ThisWorkbook object, and then click View Code on the shortcut menu.
  5. In the Object list above the Code window, select Workbook. This will automatically create an empty procedure for the Open event like this:

Private Sub Workbook_Open() End Sub 

  1. Add the following lines of code to the procedure:
Private Sub Workbook_Open()  MsgBox Date  Worksheets("Sheet1").Range("A1").Value = Date  End Sub  
  1. Switch to Microsoft Excel and save the workbook.
  2. Close and reopen the workbook. When you open the file again, Excel runs the Workbook_Open procedure, which displays today's date in a message box.
  3. Click OK in the message box.
  4. Note that cell A1 on Sheet1 also contains the date as a result of the Workbook_Open procedure.

Regards

Kumar