Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Rows("2:2").Select
  2. ActiveWindow.FreezePanes = True
  3.  
  4. Dim r As Range
  5. Set r = ActiveCell
  6. Range("A2").Select
  7. With ActiveWindow
  8. .FreezePanes = False
  9. .ScrollRow = 1
  10. .ScrollColumn = 1
  11. .FreezePanes = True
  12. .ScrollRow = r.Row
  13. End With
  14. r.Select
  15.  
  16. With ActiveWindow
  17. .SplitColumn = 0
  18. .SplitRow = 1
  19. End With
  20. ActiveWindow.FreezePanes = True
  21.  
  22. Application.ScreenUpdating = True
  23. Cells(2, 1).Select
  24. ActiveWindow.FreezePanes = True
  25.  
  26. Option Explicit
  27.  
  28. Sub xls_Build__Report()
  29. Dim xlApp As Excel.Application, ws As Worksheet, wb As Workbook
  30. Dim fn As String
  31.  
  32. Set xlApp = CreateObject("Excel.Application")
  33. xlApp.DisplayAlerts = False
  34. xlApp.Visible = True
  35.  
  36. Set wb = xlApp.Workbooks.Add
  37. With wb
  38. .Sheets(1).Name = "Report"
  39. With .Sheets("Report")
  40.  
  41. 'report generation here
  42.  
  43. End With
  44.  
  45. 'This is where the Freeze Pane is dealt with
  46. 'Freezes top row
  47. With xlApp.ActiveWindow
  48. .SplitColumn = 0
  49. .SplitRow = 1
  50. .FreezePanes = True
  51. End With
  52.  
  53. fn = CurrentProject.Path & "ReportsReport_" & Format(Date, "yyyymmdd") & ".xlsx"
  54. If CBool(Len(Dir(fn, vbNormal))) Then Kill fn
  55. .SaveAs FileName:=fn, FileFormat:=xlOpenXMLWorkbook
  56. End With
  57.  
  58. Close_and_Quit:
  59. wb.Close False
  60. xlApp.Quit
  61. End Sub
  62.  
  63. Rows("2:2").Select
  64. ActiveWindow.FreezePanes = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement