Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
ektarathi
New Contributor III

Leading zeroes are dropped while exporting to excel using macro


Hi All,

I am using below mentioned macro to export 2 objects to excel using a button.My data exports to excel fine, but when I look at some fields like emplid, location cd etc, the leading zeroes are dropped. Could someone please help me with this?    

sub ExcelFile

Path = "C:\temp\"
FileName = "Test_" & GetFormattedDate  & ".xlsx"

set XLApp = CreateObject("Excel.Application")

XLApp.Visible = true
set XLDoc = XLApp.Workbooks.Add

ActiveDocument.GetSheetObject("CH04").CopyTableToClipboard true
XLDoc.Sheets(1).Paste()

XLDoc.Sheets(1).Rows("1:3000").EntireRow.AutoFit


ActiveDocument.GetSheetObject("CH01").CopyTableToClipboard true
XLDoc.Sheets(2).Paste()

XLDoc.Sheets(2).Rows("1:3000").EntireRow.AutoFit

'ActiveDocument.GetSheetObject("CH24").CopyTableToClipboard true
'XLDoc.Sheets(3).Paste()

'XLDoc.Sheets(3).Rows("1:3000").EntireRow.AutoFit

XLDoc.Sheets(1).Name = "Page One"
XLDoc.Sheets(2).Name = "Page Two"
'XLDoc.Sheets(3).Name = "Page Three"
XLDoc.Sheets(1).Range("A1").Select

end sub

3 Replies
Employee
Employee

Re: Leading zeroes are dropped while exporting to excel using macro

What if you convert your field to text by using the text() function before executing the macro? will it still export it as a text?

Re: Leading zeroes are dropped while exporting to excel using macro

Perhaps this discussion helps: Re: Export to Excel via macro-number format


talk is cheap, supply exceeds demand
ektarathi
New Contributor III

Re: Leading zeroes are dropped while exporting to excel using macro

Thanks for the reply Agis,

My field is already formatted to text.But it loses the format in the excel :-( Any other suggestions?

Community Browser