XL 2019 L'indice n'appartient pas à la sélection

Afro

XLDnaute Nouveau
Bonjour j'aimerais que vous m'aidiez à débugué mon code :
Sub SauvegarderFacture()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim cheminwk2 As String
Range("Invoice").Value = Range("Facture").Value
'ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & "Facture" & "\" & Range("C7").Value & "-" & Range("C16").Value, FileFormat:=xlOpenXMLWorkbook
Set wb1 = ThisWorkbook
'Set wb2 = ActiveWorkbook
'cheminwk2 = ThisWorkbook.Path & "\" & "Sauvegarde" & ".xlsm"
cheminwk2 = "C:\Users\ThinkCentre\Desktop\Sauvegarde.xlsm"
Workbooks.Open cheminwk2
Set wb2 = ActiveWorkbook
wb1.Sheets("Invoice").Copy after:=wb2.Sheets(Sheets.Count)
activesheets.Name = ActiveSheet.Range("C8").Value & "-" & Year(ActiveSheet.Range("F5").Value)
End Sub
 
Solution
Bonjour,

Sub SauvegarderFacture()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim cheminwk2 As String
Dim invoiceSheet As Worksheet

' Copy data from "Facture" to "Invoice" sheet
Set invoiceSheet = ThisWorkbook.Sheets("Invoice")
invoiceSheet.Range("Facture").Value = invoiceSheet.Range("Invoice").Value

' Save current workbook path
Set wb1 = ThisWorkbook

' Open the destination workbook
cheminwk2 = "C:\Users\ThinkCentre\Desktop\Sauvegarde.xlsm"
Set wb2 = Workbooks.Open(cheminwk2)

' Copy the "Invoice" sheet to the destination workbook
invoiceSheet.Copy After:=wb2.Sheets(wb2.Sheets.Count)

' Rename the new sheet
With wb2.ActiveSheet
.Name =...

Volvo64400

XLDnaute Nouveau
Bonjour,

Sub SauvegarderFacture()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim cheminwk2 As String
Dim invoiceSheet As Worksheet

' Copy data from "Facture" to "Invoice" sheet
Set invoiceSheet = ThisWorkbook.Sheets("Invoice")
invoiceSheet.Range("Facture").Value = invoiceSheet.Range("Invoice").Value

' Save current workbook path
Set wb1 = ThisWorkbook

' Open the destination workbook
cheminwk2 = "C:\Users\ThinkCentre\Desktop\Sauvegarde.xlsm"
Set wb2 = Workbooks.Open(cheminwk2)

' Copy the "Invoice" sheet to the destination workbook
invoiceSheet.Copy After:=wb2.Sheets(wb2.Sheets.Count)

' Rename the new sheet
With wb2.ActiveSheet
.Name = .Range("C8").Value & "-" & Year(.Range("F5").Value)
End With

' Save and close the destination workbook
wb2.Close SaveChanges:=True

' Reactivate the original workbook
wb1.Activate
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 228
Messages
2 086 421
Membres
103 205
dernier inscrit
zch