我试图从复制文件中的细胞,表1对文件B,表已创建1文件,我创造了我的代码文件B:
Sub Save()
Dim directory, fileName As String
Dim nbLigneImportCanope As Integer
Application.ScreenUpdating = False
'' Path
directory = "\\path\"
'' Number of line in file A
nbLigneImportCanope = 1
While ThisWorkbook.Worksheets("Kibana").Range("A" & nbLigneImportCanope).Value <> ""
nbLigneImportCanope = nbLigneImportCanope + 1
Wend
nbLigneImportCanope = nbLigneImportCanope - 1
'' Copy from file A
ThisWorkbook.Worksheets("Kibana").Range("A1" & ":V" & nbLigneImportCanope).Copy
'' Creation of file B
fileName = InputBox("Entrer le nom du fichier :", "Création d'un nouveau fichier...", "KIBANA_01022019")
If fileName <> "" Then
Set NewWkbk = Workbooks.Add
NewWkbk.SaveAs directory & "\" & fileName
End If
'' Paste in file B
ActiveSheet.Paste
End Sub
但我最终的
错误1004 - 粘贴的方法工作表类失败。
我检查,该位的代码之前实现:
'' Creation of file B
fileName = InputBox("Entrer le nom du fichier :", "Création d'un nouveau fichier...", "KIBANA_01022019")
剪贴板是好,用正确的数据我想粘贴,并在之后将它,它是空的。
您有任何的想法?
作为cyboashu在他的评论中写道,你应该只打开新的工作簿后复制。另外,它可以赋予目标范围为参数的Copy
命令。
此外,在你的代码你缺少的else
的If fileName <> ""
分支,所以没有选择文件名时,你会粘贴到任何表处于活动状态在那一刻的数据。
您的代码可能看起来像
'' Creation of file B
fileName = InputBox("Entrer le nom du fichier :", "Création d'un nouveau fichier...", "KIBANA_01022019")
If fileName <> "" Then
Set NewWkbk = Workbooks.Add
NewWkbk.SaveAs directory & "\" & fileName
else
exit sub ' (or whatever you want to do)
End If
ThisWorkbook.Worksheets("Kibana").Range("A1" & ":V" & nbLigneImportCanope).Copy _
NewWkbk.WorkSheets(1).Range("A1")