Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.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
需要打开两个excel文件,并使用vba将其中的数字添加到第三个文件中_Excel_Excel 2007_Vba - Fatal编程技术网

需要打开两个excel文件,并使用vba将其中的数字添加到第三个文件中

需要打开两个excel文件,并使用vba将其中的数字添加到第三个文件中,excel,excel-2007,vba,Excel,Excel 2007,Vba,我有两个excel文件,它们具有相似的格式,并且数据从单元格b15:h31相互映射。第15行是标题,B列也是。我想逐个单元格读取file1,并将该单元格的内容添加到文件2中的相应单元格,即文件1中的C16添加到文件2中的C16,文件1中的C17添加到文件2中的C17,依此类推。输出进入文件3或任何内容。尝试通过vba实现,但至今没有成功。有人知道怎么做吗。我不知道确切的编码,但我会: open both files to read from open 3rd file to write to r

我有两个excel文件,它们具有相似的格式,并且数据从单元格b15:h31相互映射。第15行是标题,B列也是。我想逐个单元格读取file1,并将该单元格的内容添加到文件2中的相应单元格,即文件1中的C16添加到文件2中的C16,文件1中的C17添加到文件2中的C17,依此类推。输出进入文件3或任何内容。尝试通过vba实现,但至今没有成功。有人知道怎么做吗。

我不知道确切的编码,但我会:

open both files to read from
open 3rd file to write to
read in the first line from the first and second file
split these two lines with the separator used into an array of values
      (for instance I seperate cells with a comma when writing to an excel file)
go through these array (this would equate to going through a row in both files)
  foreach value in the array add the value from the first with the value from the second
  print it to the 3rd file and the print the cell separator (comma)
go on to the next value until you reach the end of the 'row'
print a newline character into the 3rd file to go to the next row
then read the next line of the first and second file, repeat til done reading files
close the input and output files

凯拉已经为你确定了逻辑。如果要查找语法,请使用

Application.Workbooks.Open ("file2.xls")
Application.Workbooks.Open ("file3.xls")
打开

Workbooks("file3.xls").Activate
激活工作簿以进行读取或写入,然后

Workbooks("file3.xls").Activate
Workbooks("file3.xls").Save
Workbooks("file3.xls").Close
保存并关闭