从多个 excel 文件创建报告,这些文件自动添加到具有不同文件名的文件夹中

Create report from multiple excel files which are added automatically to the folder with different file names

我想知道这是否可行所以请不要将其视为“为我创建我的项目”post

我们每季度向客户发送一次使用情况报告(从他们购买许可证之日起每 90 天)。此报告包含具有 30 多列原始数字数据的主要表格。

我想创建一个简单的 > 将新报表拖到文件夹 > 将主工作簿的结果粘贴到报表中

创建一个 this 显然很简单,但我想:

  1. 下载使用报告(文件名代表客户端 姓名)
  2. 将所有这些报告存储在一个文件夹中
  3. 让核心工作簿检测新文件
  4. 核心工作簿读取新的excel文件,将数据添加到核心工作簿sheet上的新文件
  5. 添加数据后删除工作簿(新的使用报告拖入文件夹)
  6. 核心工作簿从 新数据

3、4 和 5 可以用 VBA 吗?我完全不熟悉它,直到最近才发现 excel.

中宏的可能性

下面我有一个宏,可以一个一个地打开一个文件夹中的所有工作簿,您会注意到我在其中注释掉了一个部分,您可以在此处输入您的代码并对给定的工作簿执行操作。这将遍历文件夹中的每个工作簿,直到没有任何剩余。

Sub ImportMacro()

'PURPOSE: To loop through all Excel files in a user specified folder and perform a set task on them'
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog

'Values in sheets'
Dim VolatilityPortfolio As String
Dim ColValue As String
VolatilityPortfolio = "VolatilityPortfolio"

'Optimize Macro Speed'
  Application.ScreenUpdating = False
  Application.EnableEvents = False
  Application.Calculation = xlCalculationManual

'Retrieve Target Folder Path From User'
  Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)

    With FldrPicker
      .Title = "Select A Target Folder"
      .AllowMultiSelect = False
        If .Show <> -1 Then GoTo NextCode
        myPath = .SelectedItems(1) & "\"
    End With

'In Case of Cancel'
NextCode:
  myPath = myPath
  If myPath = "" Then GoTo ResetSettings

'Target File Extension (must include wildcard "*")'
  myExtension = "*.xl??"

'Target Path with Ending Extention'
  myFile = Dir(myPath & myExtension)

'Loop through each Excel file in folder'
  Do While myFile <> ""
    'Set variable equal to opened workbook'
      Set wb = Workbooks.Open(Filename:=myPath & myFile)
'-------------------- Below is the worksheet macro --------------------------'

'To open the currentworkbook
 Workbooks(myFile).activate


'---------------------------- Above is the worksheet macro ----------------------- '
'Save and Close Workbook as CSV'
      wb.Close SaveChanges:=True


    'Get next file name'
      myFile = Dir
  Loop

'Message Box when tasks are completed'
  MsgBox "Task Complete!"

ResetSettings:
  'Reset Macro Optimization Settings'
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub