我目前需要对我的代码进行一些编辑,以防止它打开但不太确定要替换它的代码。所以这是我的代码
Sub CopyPasteForm()
Dim Name As String, Age As Integer, Class As String, Diploma As String,
ContactNo As String, Hobby As String, Address As String, wkbook As Workbook
Worksheets("Sheet1").Select
Name = Range("B4")
Age = Range("B6")
Class = Range("B8")
Diploma = Range("B10")
ContactNo = Range("B15")
Hobby = Range("B17")
Address = Range("B19")
Set wkbook = Workbooks.Open("C:\Users\Desktop\database.xlsx")
Worksheets("sheet1").Select
Worksheets("sheet1").Range("A1").Select
RowCount = Worksheets("sheet1").Range("A1").CurrentRegion.Rows.Count
With Worksheets("sheet1").Range("A1")
.Offset(RowCount, 0) = Name
.Offset(RowCount, 2) = Age
.Offset(RowCount, 3) = Class
.Offset(RowCount, 4) = Diploma
.Offset(RowCount, 5) = ContactNo
.Offset(RowCount, 6) = Hobby
.Offset(RowCount, 7) = Address
End With
wkbook.Save
End Sub
我知道
Set wkbook = Workbooks.Open("C:\Users\Desktop\database.xlsx")
需要更改,但我不知道如何在不使用' open'
的情况下从目录设置工作簿