运行此代码时,在此行代码中出现以下错误“运行时错误'438':对象不支持此属性或方法”:
'复制源书中的范围
wbFrom.Range(“ A:A”)。Copy
Sub CopyOpenItems()
'
' CopyOpenItems Macro
' Copy open items to sheet.
'
' Keyboard Shortcut: Ctrl+Shift+O
'
Dim wbTarget As Workbook 'workbook where the data is to be pasted
Dim wbFrom As Workbook 'workbook from where the data is to be copied
Dim wsFrom As Worksheet
Dim wsTarget As Worksheet
'set to the current active workbook (the source book)
Set wbTarget = ActiveWorkbook
Set wsTarget = wbTarget.Worksheets(1)
'open a workbook that has same name as the sheet name
Set wbFrom = Workbooks.Open("......")
Set wsFrom = wbFrom.Worksheets(1)
'activate the source book
wbFrom.Activate
'clear any thing on clipboard to maximize available memory
Application.CutCopyMode = False
'copy the range from source book
wbFrom.Range("A:A").Copy
'paste the data on the target book
wbTarget.Range("A:A").PasteSpecial
wbFrom.Range("C:C").Copy
wbTarget.Range("C:C").PasteSpecial
wbFrom.Range("D:D").Copy
wbTarget.Range("D:D").PasteSpecial
wbFrom.Range("F:F").Copy
wbTarget.Range("F:F").PasteSpecial
wbFrom.Range("J:J").Copy
wbTarget.Range("J:J").PasteSpecial
wbFrom.Range("K:K").Copy
wbTarget.Range("K:K").PasteSpecial
'clear any thing on clipboard to maximize available memory
Application.CutCopyMode = False
'save the target book
wbTarget.Save
wbFrom.Save
'close the workbook
wbFrom.Close
'activate the source book again
wbFrom.Activate
'clear memory
Set wbTarget = Nothing
Set wbFrom = Nothing
End Sub
我不知道这是怎么回事。我想代码的重点很简单,可以从一个工作簿中复制选定的列,然后将其粘贴到另一个工作簿中。 此外,此代码是在此链接上可以找到的代码的略微修改版本 https://ccm.net/faq/24666-copy-data-to-another-workbook-in-excel