0

我有 2 张纸,其中一张有 2 个按钮BrowsefileOpenfile一个 textbox TextBox1。我使用Browsefile按钮选择要打开的文件并使用Openfile按钮打开工作簿。

问题是,它会在新工作簿中打开,而不是将其添加到我的活动工作簿中。我怎么能解决这个问题?

Public fileStr As String
Sub GetOpenFile()

fileStr = Application.GetOpenFilename()
Worksheets("Sheet1").TextBox1.Value = fileStr

End Sub
Sub Paste_Click()
Dim wbk1 As Workbook, wbk2 As Workbook

Set wbk1 = ActiveWorkbook
Set wbk2 = Workbooks.Add(fileStr)

wbk2.Sheets(1).Cells.Copy wbk1.Worksheets("Sheet2").Cells(1, 1)

End Sub
4

1 回答 1

1

试试这个:) 它将允许您选择文件并在打开的工作簿末尾复制第一张工作表。

Sub Paste_Click()
Dim wbk1 As Workbook, wbk2 As Workbook

fileStr = Application.GetOpenFilename()

Set wbk1 = ActiveWorkbook
Set wbk2 = Workbooks.Add(fileStr)

wbk2.Sheets("Sheet1").Copy After:=Workbooks("WorkbookNameYouCopyCodeInto").Sheets(3)
wbk2.Close
End Sub
于 2012-10-10T12:44:20.380 回答