3 Replies Latest reply: May 14, 2015 12:27 PM by ekta rathi RSS

    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