JIM74
Aerospace
- Jun 29, 2006
- 3
How do I access the data from an Excel table using a VB Script macro?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
dim xlApp 'Excel Application Object
dim xlWorkbook 'Excel Workbook object
dim sWkBkPath 'String
set xlApp = CreateObject("Excel.Application")
sWkBkPath = InputBox("Enter the path to the desired workbook")
set xlWorkbook = xlApp.Workbooks.Open(sWkBkPath)
xlApp.Visible = True 'Un-Comment this line if you want to see the workbook
'**************************
'Here is where you can access the data in the
'excel file with lines like this, which returns
'the value of the text in cell "C5" (Row 5, Column 3)
MsgBox xlApp.ActiveSheet.Cells(5,3).Text
'**************************
'xlWorkbook.Save 'Do this if you intend to make and save changes
xlWorkbook.Close
xlApp.Quit
set xlWorkbook = Nothing
set xlApp = Nothing
dim xlApp 'Excel Application Object
dim xlWorkbook 'Excel Workbook object
dim sWkBkPath 'String
dim nRow
dim nCol
dim sPartNumber
set xlApp = CreateObject("Excel.Application")
sWkBkPath = InputBox("Enter the path to the desired workbook")
set xlWorkbook = xlApp.Workbooks.Open(sWkBkPath)
'xlApp.Visible = True 'Un-Comment this line if you want to see the workbook
'**************************
'Here is where you can access the data in the
'excel file
nCol = 3 'Change this to whatever column you're using
nRow = 1 'Change this to the first row you want to process
sPartNumber = xlApp.ActiveSheet.Cells(nRow, nCol).Text
'While loop will exit when a blank cell is reached. This assumes that
'your part number list is continuous with no blanks
While sPartNumber <> ""
'Do your processing here
nRow = nRow + 1
sPartNumber = xlApp.ActiveSheet.Cells(nRow, nCol).Text
Wend
'**************************
'xlWorkbook.Save 'Do this if you intend to make and save changes
xlWorkbook.Close
xlApp.Quit
set xlWorkbook = Nothing
set xlApp = Nothing