VBS to combine Excel columns



我正在寻找可以自动将所有列组合为单个列的VBS,表到列…谢谢您的支持。

ROW1| A D G


ROW3| C F I

预期结果:


B
C
D
E
F
G
H

你可以这样开始:

Option Explicit
'Var's Used
Dim oXLApp, oSheet, sXlFile, sWorkSheet, iStartRow, iEndRow
Dim iStartColumn, iEndColumn, iRowIndex, iColIndex, sValue
'Set file path and name to excel file that contains the data
sXlFile = "E:Sample.xls"
sWorkSheet = "Sheet1"
'Set the start & end rows and columns
iStartRow = 1
iEndRow = 3
iStartColumn = 1
iEndColumn = 3
'Create the excel object
Set oXLApp = CreateObject("Excel.Application")
'Make it visible
oXLApp.Visible = True
'Open the workbook
oXLApp.Workbooks.Open(sXlFile)
'Create the worksheet object
Set oSheet = oXLApp.Sheets(sWorkSheet)
'Row loop
For iRowIndex = iStartRow To iEndRow
  'Column loop
  For iColIndex = iStartColumn To iEndColumn
    'Get the Value of the cell
    sValue = oSheet.Cells(iRowIndex,iColIndex).Value
    'So something with the value
    WScript.Echo sValue
  Next
Next
'Distroy the sheet object
Set oSheet = Nothing
'Close the workbook
oXLApp.Workbooks.Close
'Exit Excel
oXLApp.Quit
'Distroy the XLApp object
Set oXLApp = Nothing

最新更新