简体   繁体   中英

VBA/Excel - clipboard empty after workbook SaveAs

After 10 years, I find myself making my first post. I've search endlessly for a solution to no avail. I want to:

  • copy a range of cells
  • save and close the workbook
  • user can paste to another application

I haven't even closed the workbook in the code below, yet there's nothing on the clipboard after the SaveAs.

Sub Test()
     Application.CutCopyMode = True
     ActiveWorkbook.Sheets(1).Range("A1:C5").Copy
     ActiveWorkbook.SaveAs Filename:="F:\Test.xlsx"
End Sub

Setting CutCopyMode to False yields the same results. I can paste no problem if I exclude the SaveAs line.

Since there are no changes to the workbook after you save, you can simply switch the lines and get your desired end result.

Sub Test()
     Application.CutCopyMode = True
     ActiveWorkbook.SaveAs Filename:="F:\Test.xlsx"
     ActiveWorkbook.Sheets(1).Range("A1:C5").Copy
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM