Advertisement
Guest User

Untitled

a guest
Mar 6th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.27 KB | None | 0 0
  1. Option Explicit
  2.  
  3.     '-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  4.     '~Input file path here in between the quotation marks
  5.     Const FILE_PATH As String = "C:\file.xlsx"
  6.  
  7.     '~Input name of Sheet with Pivot Tables here in between the quotation marks
  8.     Const PIVOT_SHEET_NAME As String = "IQ_Pivot"
  9.     '-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  10. Sub Excelthingtest()
  11.     Dim arrayOfData As Variant
  12.     arrayOfData = GetData()    
  13. End Sub
  14.  
  15. Private Function GetData() As Variant
  16.     Dim excelApplication As Object
  17.     Set excelApplication = CreateObject("Excel.Application")
  18.     Dim targetBook As Object
  19.     Set targetBook = excelApp.Workbooks.Open(FILE_PATH)
  20.     Dim targetSheet As Object
  21.     Set targetSheet = targetBook.Sheets(PIVOT_SHEET_NAME)
  22.     Dim targetLastRow As Long
  23.     Dim targetLastColumn As Long
  24.     targetLastRow = targetSheet.Cells(Rows.Count, 1).End(-4162).Row
  25.     targetLastColumn = targetSheet.Cells(1, Columns.Count).End(-4159).Column
  26.     GetData = targetSheet.Range(Cells(1, 1), Cells(targetLastRow, targetLastColumn))
  27.     excelApplication.DisplayAlerts = False
  28.     excelApplication.Quit
  29. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement