0
ファイルダイアログを使用して、さまざまなExcelファイルからデータをコピーし、1つのワークシートに貼り付けます。ただし、2番目のファイルは最初のファイルのデータを上書きします。最初のデータは、宛先ワークブックの範囲A2:E2710に貼り付けられました。データ範囲の2番目のセットがA2:A118の場合、宛先ブックのA2:A118が上書きされます。以前に貼り付けたデータを貼り付けて上書きしないようにするにはどうすればよいですか? Selection.Insert Shift:= xlDownを試しましたが、データを貼り付けません。助けてください。前回のデータを上書きせずにコピーしたセルを貼り付け
Sub FASB_Select()
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Set ExcelSheet = CreateObject("Excel.Sheet")
'Declare a variable to contain the path
'of each selected item. Even though the path is a String,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant
'Use a With...End With block to reference the FileDialog object.
With fd
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
Sheets("Data").Select
'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
'vrtSelectedItem is a String that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this path.
'This example simply displays the path in a message box.
ThisWorkbook.FollowHyperlink (vrtSelectedItem)
'Clear CutCopyMode
Application.CutCopyMode = False
'Wait some time
Application.Wait Now + TimeValue("00:00:01") ' wait 3 seconds
DoEvents
'IN Excel :
'SELECT ALL
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
'EXIT (Close & Exit)
Application.Wait Now + TimeValue("00:00:01") ' wait 3 seconds
ActiveWorkbook.Close SaveChanges:=False
'Wait some time
Application.Wait Now + TimeValue("00:00:01") ' wait 3 seconds
Range("A2").Select
'Paste
ActiveSheet.Paste
Next vrtSelectedItem 'Loop for each file selected in the file dialog box
'Exit if the user pressed Cancel
Else
Exit Sub
End If
End With
'Set the object variable to Nothing
Set fd = Nothing
End Sub
*各セクションを貼り付ける必要がありますか? –