我能够创建一个打开工作簿的程序,该工作簿可以复制并粘贴到本案例中调用的工作簿中#34;所有WIP"。但是,为了使这更方便,我希望如此,无论您运行哪个工作簿,它都将复制并粘贴到该特定工作簿中。感谢。
Sub AddMaskLevels()
Dim book
Set book = Workbooks.Open("MaskLevels.xlsx")
Dim x As Workbook
Dim y As Workbook
Set x = Workbooks("MaskLevels.xlsx")'Where the information is copied from'
Set y = Workbooks("ALL WIP.xlsm")'I want to make this into the active workbook'
x.Sheets("Sheet1").Range("A1:A81").Copy
y.Sheets("All WIP").Columns(9).End(xlDown).Offset(1, 0).PasteSpecial 'The Sheet and column will always stay the same'
x.Save
x.Close
End Sub
答案 0 :(得分:0)
如果要从MaskLevels.xlsx
复制到运行宏的工作簿中,请尝试:
Sub AddMaskLevels()
Dim y As Workbook
Dim x As Workbook
Set y = ThisWorkbook
Set x = Workbooks.Open("MaskLevels.xlsx")
x.Sheets("Sheet1").Range("A1:A81").Copy
y.Sheets("All WIP").Columns(9).End(xlDown).Offset(1, 0).PasteSpecial
'Close the workbook (no need to save it - hopefully nothing was changed)
x.Close False
End Sub
如果要在运行宏时从MaskLevels.xlsx
复制到活动的任何工作簿,请尝试:
Sub AddMaskLevels()
Dim y As Workbook
Dim x As Workbook
Set y = ActiveWorkbook
Set x = Workbooks.Open("MaskLevels.xlsx")
x.Sheets("Sheet1").Range("A1:A81").Copy
y.Sheets("All WIP").Columns(9).End(xlDown).Offset(1, 0).PasteSpecial
'Close the workbook (no need to save it - hopefully nothing was changed)
x.Close False
End Sub