VBA creer nouveau document a emplacement definis et changer le nom

Bien le bonjour, Je suis vraiment loins de l'expertise de plusieurs, mais j'apprends!!!

Ce code fait une verification specifique d'une cellule (cette partie de code fonctionne)

si pas d'erreurs, je souhaite que:

Un nouveau document soit creer dans un repertoire specifique definie a la cellule A1 de l'onglet master

ce nouveau document se nomme : Rapport_yymmdd

les valeurs de l'onglet rapport soient copiees puis inserees dans un onglet du document creer

sortir en PDF l'onglet rapport dans un repertoire specifique definie a la cellule A1 de l'onglet master sous le nom Rapport_yymmdd

Pourquoi ca ne fonctionne pas!

votre aide sera grandement apprecie, je tourne en rond....

Sub ErrorCheck()

Dim wkb As Workbook: Set wkb = ThisWorkbook
Dim wsRap As Worksheet, ws As Worksheet
Dim wkbNew As Workbook
Dim fromPath As String

Set wsRap = wkb.Sheets("Rapport")
Set ws = wkb.Sheets("ERROR")

    If ws.Range("C1").DisplayFormat.Interior.Color = vbRed Then
        MsgBox "An error is detected. "
        ws.Activate

    End If

       If ws.Range("C1").DisplayFormat.Interior.Color = vbGreen Then
        MsgBox "No errors detected, the report will now print to pdf to X location & Save the Report in a new Excel document."
        wkb.Save

'A partir d'ici, oufffff ca ne fonctionne pas tant. 

        fromPath = Sheets("MASTER").Range("A1")
If Right(fromPath, 1) <> "\" Then fromPath = fromPath & "\"

Set wkbNew = wkbNew.Add.SaveAs(fromPath & ("Rapport") & Format(Date, "yymmdd"))

 wsRap.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fromPath & ("Report name") & Format(Date, "yymmdd")

        wsRap.Range("A1:B3").Copy
        wkbNew.Range("A1").PasteSpecial Paste:=xlPasteValues

    End If

End Sub

Bonjour,

Voila ton code fonctionnel

cdlt

Sub ErrorCheck()

Dim wkb As Workbook: Set wkb = ThisWorkbook
Dim wsRap As Worksheet, ws As Worksheet
Dim wkbNew As Workbook
Dim fromPath As String

Set wsRap = wkb.Sheets("Rapport")
Set ws = wkb.Sheets("ERROR")

    If ws.Range("C1").DisplayFormat.Interior.Color = vbRed Then
        MsgBox "An error is detected. "
        ws.Activate

    End If

       If ws.Range("C1").DisplayFormat.Interior.Color = vbGreen Then
        MsgBox "No errors detected, the report will now print to pdf to X location & Save the Report in a new Excel document."
        wkb.Save

'A partir d'ici, ca fonctionne

        fromPath = Sheets("MASTER").Range("A1")
If Right(fromPath, 1) <> "\" Then fromPath = fromPath & "\"

Set wkbNew = Workbooks.Add
             With wkbNew
             .SaveAs (fromPath & ("Rapport") & Format(Date, "yymmdd"))
             End With
    wsRap.Range("A1:B3").Copy
    wkbNew.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteValues
    wkbNew.Save

 wsRap.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fromPath & ("Report name") & Format(Date, "yymmdd")
wkb.Activate
End If
End Sub

Youpi! Merci!!!!! c'est génial.

Rechercher des sujets similaires à "vba creer nouveau document emplacement definis changer nom"