Bonjour le forum,
Dans un fichier Excel, j'ai écrit une macro pour générer un document word. En voici le code :
Lorsque j'exécute cette macro une fois, tout se passe bien, mais lorsque je veux générer un 2e rapport, là ça bogue et j'ai droit au message d'erreur suivant :
"Erreur d'éxécution '462' Le serveur distant n'existe pas ou n'est pas disponible"
En choisissant le débogage, la ligne surlignée en jaune est :
.PageSetup.LeftMargin = CentimetersToPoints(1)
Quelqu'un peut-il me venir en aide ? Merci d'avance...
Dans un fichier Excel, j'ai écrit une macro pour générer un document word. En voici le code :
Code:
Sub CréerRapport()
Application.ScreenUpdating = False
Pat = ActiveWorkbook.Name
Dim appWrd As Word.Application
Dim docWrd As Word.Document
Set appWrd = New Word.Application
appWrd.Visible = False
Set docWrd = appWrd.Documents.Add
With docWrd
.PageSetup.LeftMargin = CentimetersToPoints(1)
.PageSetup.TopMargin = CentimetersToPoints(1)
.PageSetup.BottomMargin = CentimetersToPoints(1)
.PageSetup.RightMargin = CentimetersToPoints(1)
End With
Windows(Pat).Activate
Range("B2:AE51").Select
Selection.Copy
With appWrd.Selection
.Paste
.InsertBreak Type:=wdSectionBreakNextPage
End With
Windows(Pat).Activate
Range("B53:AE107").Select
Selection.Copy
With appWrd.Selection
.Paste
.InsertBreak Type:=wdSectionBreakNextPage
End With
Range("B109:AE160").Select
Selection.Copy
Range("L13").Select
With appWrd.Selection
.Paste
End With
Application.CutCopyMode = False
docWrd.SaveAs Filename:="Rapport_de_" & ActiveCell.Text & ".doc", FileFormat:=wdFormatDocument
Set docWrd = Nothing
appWrd.Quit
Set appWrd = Nothing
Windows(Pat).Activate
Range("AH9").Select
Application.ScreenUpdating = True
MsgBox " Ce rapport a bien été enregistré ! "
End Sub
"Erreur d'éxécution '462' Le serveur distant n'existe pas ou n'est pas disponible"
En choisissant le débogage, la ligne surlignée en jaune est :
.PageSetup.LeftMargin = CentimetersToPoints(1)
Quelqu'un peut-il me venir en aide ? Merci d'avance...