从另一个工作簿复制/粘贴

huangapple go评论85阅读模式
英文:

Copy/paste from another workbook

问题

这是我的代码:

Dim chemin As String
Workbooks.Open ("Z:\ext_Workbook.xlsx")
Sheets("produits").Activate
Sheets("produits").Range("A1:CZ500").Copy

ThisWorkbook.Activate
Sheets("STT").Select
ActiveSheet.Range("A1").Select
ActiveSheet.Paste

Application.DisplayAlerts = False
Workbooks("ext_Workbook.xlsx").Close

运行停在这行:

Sheets("STT").Select

但是我已经验证了,有一个名为STT的工作表,拼写也是相同的。

英文:

It is a simple task, but I don't know why it is not working…

This is my code :

Dim chemin As String
Workbooks.Open ("Z:\ext_Workbook.xlsx") 
Sheets("produits").Activate
Sheets("produits").Range("A1:CZ500").Copy 
   
ThisWorkbook.Activate
Sheets("STT").Select
ActiveSheet.Range("A1").Select
ActiveSheet.Paste
   
Application.DisplayAlerts = False
Workbooks("ext_Workbook.xlsx").Close

The run stop at the line :

 Sheets("STT").Select

But I verified, and there is a sheet named STT, with the same spelling

答案1

得分: 0

以下是翻译好的部分:

下面的代码应该适用于您

Dim SourceWBK As Workbook, DestinationWBK As Workbook

Set SourceWBK = Workbooks.Open("Z:\ext_Workbook.xlsx")
Set DestinationWBK = ThisWorkbook

SourceWBK.Worksheets("produits").Range("A1:CZ500").Copy
DestinationWBK.Worksheets("STT").Range("A1:CZ500").PasteSpecial Paste:=xlPasteAll
Application.CutCopyMode = False

Application.DisplayAlerts = False
SourceWBK.Close False

希望这对您有帮助。

英文:

The below should work for you.

Dim SourceWBK As Workbook, DestinationWBK As Workbook

Set SourceWBK = Workbooks.Open("Z:\ext_Workbook.xlsx")
Set DestinationWBK = ThisWorkbook

SourceWBK.Worksheets("produits").Range("A1:CZ500").Copy
DestinationWBK.Worksheets("STT").Range("A1:CZ500").PasteSpecial Paste:=xlPasteAll
Application.CutCopyMode = False

Application.DisplayAlerts = False
SourceWBK.Close False

huangapple
  • 本文由 发表于 2020年1月3日 20:08:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578400.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定