帮助VBA脚本

首先,我是VBA的新手,但是我想要做的是伪代码:

For All open Excel Files Copy all values in Colomns A,B, C and D Append into Tab 1 of output.xls 

我将不胜感激正确的方向。

谢谢

有时学习的最好方法就是录制一个macros。

工具>macros – selectlogging。

然后进入你的工作簿,select列A,B,C,D然后CTRL + C,然后打开你的新的TaB和CTRL + V.

停止录制macros,然后ALT + F11看到生成的代码,这应该给你一个启动十。

如果你需要帮助理解生成的代码/它做了什么回来,我们可以解释。

有一些事情,loggingmacros不会帮助你,例如,使用For … Each来遍历工作簿中的每个工作表。 以下是一些示例代码,指出您正确的方向。 这将遍历所有打开的工作簿,并将前四列的内容复制到工作表上。

 Sub joinAllSheets() Dim ws As Worksheet Dim wb As Workbook Dim wsOutput As Worksheet Dim lngRowCount As Long Dim wbSource As Workbook 'create output workbook Set wsOutput = Application.Workbooks.Add.Sheets(1) lngRowCount = 1 'Iterate through each open workbook For Each wb In Application.Workbooks 'if the current workbook is not our output workbook then If wb.Name <> wsOutput.Name Then 'iterate through each worksheet For Each ws In wb.Worksheets 'copy the first four columns of the used range in the worksheet Application.Intersect(ws.UsedRange, ws.Range("A:D")).Copy _ Destination:=wsOutput.Cells(lngRowCount, 1) 'we need to count how many rows there are in the usedrange so we know 'where to paste into the output worksheet lngRowCount = lngRowCount + ws.UsedRange.Rows.Count + 1 Next ws End If Next wb End Sub