ファイル名などに応じて、デバッグが必要になることがあります。マスターシートにコピーするときに最初の空の行にペーストすると、最初に使用されていない行番号を取得するコードを組み込む必要があります。問題はありません、私に教えてください。残りの部分は私が一緒に行ったときに説明しようとした。ご質問がありましたらお知らせください。マスターワークブックのコピーを作成し、このコードで練習するときに使用します。コピーしたブックのモジュールを開き、このコードを貼り付けます。あなたがその論理に従うことができるかどうかを見てください。
Sub getOpenExcel()
' Your daily report has a date in it's name
' to select an open workbook we must first know it's name
' AND - it must be already open
' Your examples are 2017-03-11-18875, 2017-03-12-18875, 2017-03-13-18875
' If the name is the current date then this would work to get the filename
Dim fileName As String, monthNum As String, dayNum As String, wb1 As Workbook, wb2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet, rng1 As Range, rng2 As Range
' this adds a ZERO to the front of month numbers less than 10
If Month(Date) < 10 Then
monthNum = "0" & CStr(Month(Date))
Else
monthNum = CStr(Month(Date))
End If
' You may or may not need this section
' it adds a ZERO to the front of day numbers less than 10
If Day(Date) < 10 Then
dayNum = "0" & CStr(Day(Date))
Else
dayNum = CStr(Day(Date))
End If
' many cases the daily report will come from the previous day
' If your file has yesterday's date, then comment out the above code and uncomment the following code
'
'If Day(DateAdd("d", -1, Date)) < 10 Then
' dayNum = "0" & Day(DateAdd("d", -1, Date))
'Else
' dayNum = Day(DateAdd("d", -1, Date))
'End If
fileName = CStr(Year(Date)) & "-" & monthNum & "-" & dayNum & "-" & "18875"
' if today's date is 3/14/17 then "fileNem" = "2017-03-12-18875"
' If your daily report is an excel book, then we need to add the proper extension.
' It could be one of many, "xls", ".xlsx" , ".xlsm", etc....
' If your daily report is open - look at the top. It should have the file name and extension.'
' Replace the below extension with the correct one.
fileName = fileName & ".xlsx"
' Again, if today's date is 3/14/17 then "fileNem" = "2017-03-12-18875.xlsx"
' This is where we set both workbooks to variables
'
Set wb1 = ThisWorkbook ' This is your master sheet
Set ws1 = wb1.Worksheets("Sheet1")
On Error GoTo notOpen
Set wb2 = Workbooks(fileName) ' This is your daily report
On Error GoTo 0
Set ws2 = wb2.Worksheets("Sheet1")
ws1.Activate
'*************************************************************************************
' If successful this is the area where you put your code to copy and paste automatically
'
' If you need this pasted to the first empty row at bottom of page then
' put code here to find the first empty row and use that varaible
' with range("a" & firstUnusedRow) intstead of A1 ...
wb2.Activate
Range("A1:Z500").Copy _
Destination:=wb1.Worksheets("Sheet1").Range("A1") 'change A1 to A & firstUnusedRow
'*************************************************************************************
' This is the clean up and exit code
Set wb1 = Nothing
Set wb2 = Nothing
Exit Sub
notOpen:
On Error GoTo 0
Set wb1 = Nothing
MsgBox "The file " & fileName & " is not open"
Exit Sub
End Sub
これは間違いなくVBAで行うことができます。おそらく、このページの右側にある「関連する」質問のいくつかを見直してください。 –
これは私が検索して探しているものです – donviti
彼は記事の1つを見て、次にコードを書いて、次に質問をすると言っていると思います。 http://stackoverflow.com/questions/3885733/excel-summary-of-many-excel-files-data-into-one-report-excel?rq=1。このサイトはあなたのためにあなたの仕事をするためのものではありません。 – Kevin