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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Frank_Hartmann
Master II
Master II

Excel vba macro

Hi QV Community.

I try to Export a table from Qlikview to Excel via vba macro.

I´m using the following macro:

------------------------------------------------------------------------

Sub Excel
call ExcelExport(objID)
End sub

FUNCTION ExcelExport(objID)
set obj = ActiveDocument.GetSheetObject( "TB04" )
w = obj.GetColumnCount
if obj.GetRowCount>1001 then
h=1000
else h=obj.GetRowCount
end if
Set objExcel = CreateObject("Excel.Application") 
set XLDOC = objExcel.Workbooks.open ("C:\Users\Admin\Desktop\Metrics_Macro_export.xlsx")
objExcel.Visible = True
set CellMatrix = obj.GetCells2(0,0,w,h)
column = 1
for cc=0 to w-1
objExcel.Cells(1,column).Value = CellMatrix(0)(cc).Text
objExcel.Cells(1,column).EntireRow.Font.Bold = True
column = column +1
next
c = 1
r =2
for RowIter=1 to h-1
for ColIter=0 to w-1
objExcel.Cells(r,c).Value = CellMatrix(RowIter)(ColIter).Text
c = c +1
next
r = r+1
c = 1
next

ActiveWorkbook.SaveAs ("C:\Users\Admin\Desktop\Metrics_Macro_export.xlsx")

End Function

-----------------------------------------------------------------------

So far so good. The macro opens the excelfile and it pastes the new Information into the excelfile.

But now i need to save this updated file under the same filename and path.

What am i doing wrong? The macro is not saving the updated file.

ActiveWorkbook.SaveAs seems not to be the correct command to save the open Excelfile!

Any ideas?

thx for helping

1 Solution

Accepted Solutions
marcus_sommer

Try it only with save: XLDOC.save

- Marcus

View solution in original post

3 Replies
marcus_sommer

Try it only with save: XLDOC.save

- Marcus

tamilarasu
Champion
Champion

Hi Frank,

Try,

Sub Excel
call ExcelExport(objID)
End sub

FUNCTION ExcelExport(objID)
set obj = ActiveDocument.GetSheetObject( "TB04" )
w = obj.GetColumnCount
if obj.GetRowCount>1001 then
h=1000
else h=obj.GetRowCount
end if
Set objExcel = CreateObject("Excel.Application") 
set XLDOC = objExcel.Workbooks.open ("C:\Users\Admin\Desktop\Metrics_Macro_export.xlsx")
objExcel.Visible = True
set CellMatrix = obj.GetCells2(0,0,w,h)
column = 1
for cc=0 to w-1
objExcel.Cells(1,column).Value = CellMatrix(0)(cc).Text
objExcel.Cells(1,column).EntireRow.Font.Bold = True
column = column +1
next
c = 1
r =2
for RowIter=1 to h-1
for ColIter=0 to w-1
objExcel.Cells(r,c).Value = CellMatrix(RowIter)(ColIter).Text
c = c +1
next
r = r+1
c = 1
next


ActiveWorkbook.Save

ActiveWorkbook.Close

End Function

Frank_Hartmann
Master II
Master II
Author

thank you very much