Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript 将多个excel文件中的特定列复制到另一个excel文件的单个列_Vbscript - Fatal编程技术网

Vbscript 将多个excel文件中的特定列复制到另一个excel文件的单个列

Vbscript 将多个excel文件中的特定列复制到另一个excel文件的单个列,vbscript,Vbscript,我不太熟悉VBScript,我想从多个excel工作表(Source_1.xlsx、Source_2.xlsx和Source_3.xlsx)中复制一个特定列(比如C列)。并将其粘贴到另一张excel工作表Dest.xlsx的A列。此列不应存在重复值。任何帮助都将不胜感激 首先,您需要创建excel对象,假设文件相同,并且最后使用递增整数,您可以遍历每个excel对象。在遍历时,可以调用与const相同的列,并复制到新的文件名。当您开始编写一些代码时,请返回报告,以便进一步处理 for i to

我不太熟悉VBScript,我想从多个excel工作表(Source_1.xlsx、Source_2.xlsx和Source_3.xlsx)中复制一个特定列(比如C列)。并将其粘贴到另一张excel工作表Dest.xlsx的A列。此列不应存在重复值。任何帮助都将不胜感激

首先,您需要创建excel对象,假设文件相同,并且最后使用递增整数,您可以遍历每个excel对象。在遍历时,可以调用与const相同的列,并复制到新的文件名。当您开始编写一些代码时,请返回报告,以便进一步处理

for i to x
filename = "scen_"& i & ".xlsx"
copyfilename = "copytohere.xlsx"
'set up the object

    for rowstart to rowend
    'get contents of x column
    'copy contents to copyfilename excel doc
     Loop

loop
谢谢

Const xlFilterCopy = 2
Const xlUp = -4162
Const xlDown = -4121

strPathSrc = "C:\Test" ' Source files folder
strMaskSrc = "Source_*.xlsx" ' Source files filter mask
iSheetSrc = 1 ' Sourse sheet index or name
iColSrc = 3 ' Source column index, e. g. 3 for "C"
strPathDst = "C:\Test\Dest.xlsx" ' Destination file
iColDst = 1 ' Destination column index

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkBookDst = objExcel.Workbooks.Open(strPathDst)
Set objSheetTmp = objWorkBookDst.Worksheets.Add
objSheetTmp.Cells(1, iColDst).Value = "TempHeader"
Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.NameSpace(strPathSrc)
Set objItems = objFolder.Items()
objItems.Filter 64 + 128, strMaskSrc
objExcel.DisplayAlerts = False
For Each objItem In objItems
    Set objWorkBookSrc = objExcel.Workbooks.Open(objItem.Path)
    Set objSheetSrc = objWorkBookSrc.Sheets(iSheetSrc)
    objSheetSrc.Cells(1, iColSrc).Insert xlDown
    objSheetSrc.Cells(1, iColSrc).Value = "TempHeader"
    Set objRangeSrc = GetRange(iColSrc, objSheetSrc)
    If objRangeSrc.Cells.Count > 1 then
        nNextRow = GetRange(iColDst, objSheetTmp).Rows.Count + 1
        objRangeSrc.AdvancedFilter xlFilterCopy, , objSheetTmp.Cells(nNextRow, iColDst), True
        objSheetTmp.Cells(nNextRow, iColDst).Delete xlUp
        Set objRangeTmp = GetRange(iColDst, objSheetTmp)
        Set objSheetDst = objWorkBookDst.Worksheets.Add
        objRangeTmp.AdvancedFilter xlFilterCopy, , objSheetDst.Cells(1, iColDst), True
        objSheetTmp.Delete
        Set objSheetTmp = objSheetDst
    End If
    objWorkBookSrc.Close
Next
objSheetTmp.Cells(1, iColDst).Delete xlUp
objExcel.DisplayAlerts = True

Function GetRange(iColumn, objSheet)
    With objSheet
        Set GetRange = .Range(.Cells(1, iColumn), .Cells(.Cells(.Cells.Rows.Count, iColumn).End(xlUp).Row, iColumn))
    End With
End Function