VBA取得另一个excel中的数据并在原excel中显示

Dim file As String
Private Sub openfile(ByVal Target As Range)
If Target.Row = 1 And Target.Column = 1 Then
opennextfile
End If
End Sub

 

Sub opennextfile()

With Application.FileDialog(msoFileDialogOpen)

.Filters.Add "Excel Files", "*.xls, *.xlsx"

If .Show = True Then

FileCount = .SelectedItems.Count

Filename = .SelectedItems(1)

Range("D2").Value = Filename

file = Filename

openrealy

End If

End With

End Sub

Sub openrealy()

 Workbooks.Open (file)     

  With ActiveWorkbook            

Dim i As Integer                

For i = 2 To 10                

Sheet1.Range("A" & i) = .Sheets(1).Range("A" & i).Value                

Next                

.Close

  End With    

End Sub

 

posted on 2022-08-31 14:39  dzh1990  阅读(765)  评论(0编辑  收藏  举报