OVH Cloud OVH Cloud

Set W_App = Nothing ne marche pas

14 réponses
Avatar
lou
bonjour
je me serts de ce code pour travailler un fichier word
apparament il fonctionne bien

mais apres avoir fait plusieurs essais
mon pc n'en pouvais plus et je me suis demandé pourquoi ??? apres avoir
cherché ,

je suis allé voir dans le gestionnaire des taches et la j'ai vu des
dizaines de word dans
le processus , j'ai du passer par le fin de tache pour les enlever

Set W_App = Nothing ne marche pas
comment fermer word sans qu'il reste dans le processus
je ne trouve pas la solution
un petit peu d'aide svp


voici le code en question

Private Sub Commande95_Click()
aa.Object.Application.Options.BackgroundSave = False
aa.Object.Application.Options.AllowFastSave = True
aa.Object.SaveAs "C:\PDF\TEMP.doc"

Dim W_App As Object
Set W_App = CreateObject("Word.Application")
With W_App
.Visible = False
.Documents.Open ("C:\PDF\TEMP.doc")
.Selection.HomeKey Unit:=wdStory
.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
.Selection.Copy
.ActiveDocument.Close wdDoNotSaveChanges

.Quit

Set W_App = Nothing

End With

End Sub

merci de votre aide

4 réponses

1 2
Avatar
lou
bonjour christian

un grand merci grace a ton code j'ai pu bidouiller
un truc qui fonctionne enfin
je n'ai plus de WORD non termine dans le processus

un grand merci pour ton aide
lou

"Christian HUBERT-HUGOUD- Xtrem7" a écrit dans le
message de news: co97cc$efl$
Salut,

Voici mon code :

Set WinWord = CreateObject("Word.application")

With WinWord
.WindowState = wdWindowStateMinimize
.Visible = False
If .Documents.Count = 1 Then
Set Doc = .Documents(1)
Else
Set Doc = .Documents.Add
End If
DoEvents
End With

If Doc Is Nothing Or Err <> 0 Then
If IsWordDoc Then
Doc.Close False
Set Doc = Nothing
WinWord.Quit False
DoEvents
Set WinWord = Nothing
DoEvents
End If
Exit Sub
End If

With Doc

.Activate
.OptimizeForWord97 = True
.PageSetup.PaperSize = wdPaperA4
.PageSetup.LineNumbering.Active = False
.PageSetup.Orientation = wdOrientPortrait
.PageSetup.TopMargin = CentimetersToPoints(1.5)
.PageSetup.BottomMargin = CentimetersToPoints(2)
.PageSetup.LeftMargin = CentimetersToPoints(0.5)
.PageSetup.RightMargin = CentimetersToPoints(0.5)
.PageSetup.PageWidth = CentimetersToPoints(21)
.PageSetup.PageHeight = CentimetersToPoints(29.7)
.PageSetup.VerticalAlignment = wdAlignVerticalTop
End With

With Doc
.Close False
Set Doc = Nothing
End With

WinWord.Quit False
DoEvents
Set WinWord = Nothing
DoEvents


Hope this helps...
Christian


--
Pour répondre à ce message, utilisez EXCLUSIVEMENT ce lien :
http://couriel.biz/c2h/
********************************************************


Bonjour,





Cordialement

Christian Hubert-Hugoud

"lou" a écrit dans le message de
news:41a7860b$0$25044$
> bonjour
> je me serts de ce code pour travailler un fichier word
> apparament il fonctionne bien
>
> mais apres avoir fait plusieurs essais
> mon pc n'en pouvais plus et je me suis demandé pourquoi ??? apres


avoir
> cherché ,
>
> je suis allé voir dans le gestionnaire des taches et la j'ai vu des
> dizaines de word dans
> le processus , j'ai du passer par le fin de tache pour les enlever
>
> Set W_App = Nothing ne marche pas
> comment fermer word sans qu'il reste dans le processus
> je ne trouve pas la solution
> un petit peu d'aide svp
>
>
> voici le code en question
>
> Private Sub Commande95_Click()
> aa.Object.Application.Options.BackgroundSave = False
> aa.Object.Application.Options.AllowFastSave = True
> aa.Object.SaveAs "C:PDFTEMP.doc"
>
> Dim W_App As Object
> Set W_App = CreateObject("Word.Application")
> With W_App
> .Visible = False
> .Documents.Open ("C:PDFTEMP.doc")
> .Selection.HomeKey Unit:=wdStory
> .Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> .Selection.Copy
> .ActiveDocument.Close wdDoNotSaveChanges
>
> .Quit
>
> Set W_App = Nothing
>
> End With
>
> End Sub
>
> merci de votre aide
>
>
>
>
>




Avatar
YannX
Et peux-tu diagnostiquer ?
Ne serait-ce pas que la fermeture était refusée
car Word voulait poser une question ?
@+

"lou" a écrit dans le message de
news:41a85f01$0$30711$
bonjour christian

un grand merci grace a ton code j'ai pu bidouiller
un truc qui fonctionne enfin
je n'ai plus de WORD non termine dans le processus

un grand merci pour ton aide
lou

"Christian HUBERT-HUGOUD- Xtrem7" a écrit dans le
message de news: co97cc$efl$
> Salut,
>
> Voici mon code :
>
> Set WinWord = CreateObject("Word.application")
>
> With WinWord
> .WindowState = wdWindowStateMinimize
> .Visible = False
> If .Documents.Count = 1 Then
> Set Doc = .Documents(1)
> Else
> Set Doc = .Documents.Add
> End If
> DoEvents
> End With
>
> If Doc Is Nothing Or Err <> 0 Then
> If IsWordDoc Then
> Doc.Close False
> Set Doc = Nothing
> WinWord.Quit False
> DoEvents
> Set WinWord = Nothing
> DoEvents
> End If
> Exit Sub
> End If
>
> With Doc
>
> .Activate
> .OptimizeForWord97 = True
> .PageSetup.PaperSize = wdPaperA4
> .PageSetup.LineNumbering.Active = False
> .PageSetup.Orientation = wdOrientPortrait
> .PageSetup.TopMargin = CentimetersToPoints(1.5)
> .PageSetup.BottomMargin = CentimetersToPoints(2)
> .PageSetup.LeftMargin = CentimetersToPoints(0.5)
> .PageSetup.RightMargin = CentimetersToPoints(0.5)
> .PageSetup.PageWidth = CentimetersToPoints(21)
> .PageSetup.PageHeight = CentimetersToPoints(29.7)
> .PageSetup.VerticalAlignment = wdAlignVerticalTop
> End With
>
> With Doc
> .Close False
> Set Doc = Nothing
> End With
>
> WinWord.Quit False
> DoEvents
> Set WinWord = Nothing
> DoEvents
>
>
> Hope this helps...
> Christian
>
>
> --
> Pour répondre à ce message, utilisez EXCLUSIVEMENT ce lien :
> http://couriel.biz/c2h/
> ********************************************************
>
>
> Bonjour,
>
>
>
>
>
> Cordialement
>
> Christian Hubert-Hugoud
>
> "lou" a écrit dans le message de
> news:41a7860b$0$25044$
> > bonjour
> > je me serts de ce code pour travailler un fichier word
> > apparament il fonctionne bien
> >
> > mais apres avoir fait plusieurs essais
> > mon pc n'en pouvais plus et je me suis demandé pourquoi ??? apres
avoir
> > cherché ,
> >
> > je suis allé voir dans le gestionnaire des taches et la j'ai vu des
> > dizaines de word dans
> > le processus , j'ai du passer par le fin de tache pour les enlever
> >
> > Set W_App = Nothing ne marche pas
> > comment fermer word sans qu'il reste dans le processus
> > je ne trouve pas la solution
> > un petit peu d'aide svp
> >
> >
> > voici le code en question
> >
> > Private Sub Commande95_Click()
> > aa.Object.Application.Options.BackgroundSave = False
> > aa.Object.Application.Options.AllowFastSave = True
> > aa.Object.SaveAs "C:PDFTEMP.doc"
> >
> > Dim W_App As Object
> > Set W_App = CreateObject("Word.Application")
> > With W_App
> > .Visible = False
> > .Documents.Open ("C:PDFTEMP.doc")
> > .Selection.HomeKey Unit:=wdStory
> > .Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > .Selection.Copy
> > .ActiveDocument.Close wdDoNotSaveChanges
> >
> > .Quit
> >
> > Set W_App = Nothing
> >
> > End With
> >
> > End Sub
> >
> > merci de votre aide
> >
> >
> >
> >
> >
>
>




Avatar
lou
bon je vais essaye d'etre plus clair que mes post precedents

avec ce code j'execute 2 actions
ACTION 1 ) dans un form j'ai un champ ole (aa) qui contiens un doc word
je clic dessus il s'ouvre j'ecris mon texte je le referme
et il me crée un fichier word dand le repertoire "C:PDFTEMP.doc"

pour fair ça avant j'avais le code suivant
-----------------------------------------------------------------
aa.Object.Application.Options.BackgroundSave = True
aa.Object.Application.Options.AllowFastSave = True
aa.Object.SaveAs "C:PDFTEMP.doc"
----------------------------------------------------------------

ACTION 2 )le reste du code sert pour copier le contenu du fichier word dans
un champ memo (recuptexte) qui est dans le form en question

pour faire ça j'ai le code suivant
---------------------------------------------------------------------------
Dim W_App As Object
Set W_App = CreateObject("Word.Application")
With W_App
.Visible = False
.Documents.Open ("C:PDFTEMP.doc")
.Selection.HomeKey Unit:=wdStory
.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
.Selection.Copy
.ActiveDocument.Close (wdDoNotSaveChanges)

W_App.Quit
End With
Set W_App = Nothing

Me.recuptexte.SetFocus
DoCmd.RunCommand acCmdPaste


FIN
-----------------------------------------
-----------------------------------------
le probleme de l'instance WORD qui reste coincée dans le gestionnaire des
taches ou plutot dans le processus
viens de ACTION 1 c'est a dire ça
------------------------------------------------------------------
aa.Object.Application.Options.BackgroundSave = True
aa.Object.Application.Options.AllowFastSave = True
aa.Object.SaveAs "C:PDFTEMP.doc"
---------------------------------------------------------
pourquoi??????? parceque il n'y a rien pour fermer le doc
et rendre la main au processeur (je supose)


alors j'ai fait ça pour l'ACTION 1( pour la 2eme il n'y a pas de probleme)

ACTION 1

On Error Resume Next
Dim WinWord
Set WinWord = CreateObject("Word.application")
With WinWord
.WindowState = wdWindowStateMinimize
.Visible = False
aa.Object.Application.Options.BackgroundSave = True
aa.Object.Application.Options.AllowFastSave = True
aa.Object.SaveAs "C:PDFTEMP.doc"
WinWord.Quit False
DoEvents
End With
Set WinWord = Nothing
DoEvents
---------------------------------------------------------

ACTION 2
'''''''''''''''''''''''''''''''''''''''''''''''''

Dim W_App As Object

Set W_App = CreateObject("Word.Application") '''ça on peux l enlever
With W_App
.Visible = False
.Documents.Open ("C:PDFTEMP.doc")
.Selection.HomeKey Unit:=wdStory
.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
.Selection.Copy
.ActiveDocument.Close (wdDoNotSaveChanges)

W_App.Quit


End With
Set W_App = Nothing

FIN

il y a encore un tout petit probleme c'est que ça marche 10x et ça peux
rater une fois
il faudrait ameliorer mais je ne suis pas tres calé en vb


si tu peux ameliorer je suis preneur
encore merci de ton aide d'hier
lou






"YannX" a écrit dans le message de news:

Et peux-tu diagnostiquer ?
Ne serait-ce pas que la fermeture était refusée
car Word voulait poser une question ?
@+

"lou" a écrit dans le message de
news:41a85f01$0$30711$
> bonjour christian
>
> un grand merci grace a ton code j'ai pu bidouiller
> un truc qui fonctionne enfin
> je n'ai plus de WORD non termine dans le processus
>
> un grand merci pour ton aide
> lou
>
> "Christian HUBERT-HUGOUD- Xtrem7" a écrit dans le
> message de news: co97cc$efl$
> > Salut,
> >
> > Voici mon code :
> >
> > Set WinWord = CreateObject("Word.application")
> >
> > With WinWord
> > .WindowState = wdWindowStateMinimize
> > .Visible = False
> > If .Documents.Count = 1 Then
> > Set Doc = .Documents(1)
> > Else
> > Set Doc = .Documents.Add
> > End If
> > DoEvents
> > End With
> >
> > If Doc Is Nothing Or Err <> 0 Then
> > If IsWordDoc Then
> > Doc.Close False
> > Set Doc = Nothing
> > WinWord.Quit False
> > DoEvents
> > Set WinWord = Nothing
> > DoEvents
> > End If
> > Exit Sub
> > End If
> >
> > With Doc
> >
> > .Activate
> > .OptimizeForWord97 = True
> > .PageSetup.PaperSize = wdPaperA4
> > .PageSetup.LineNumbering.Active = False
> > .PageSetup.Orientation = wdOrientPortrait
> > .PageSetup.TopMargin = CentimetersToPoints(1.5)
> > .PageSetup.BottomMargin = CentimetersToPoints(2)
> > .PageSetup.LeftMargin = CentimetersToPoints(0.5)
> > .PageSetup.RightMargin = CentimetersToPoints(0.5)
> > .PageSetup.PageWidth = CentimetersToPoints(21)
> > .PageSetup.PageHeight = CentimetersToPoints(29.7)
> > .PageSetup.VerticalAlignment = wdAlignVerticalTop
> > End With
> >
> > With Doc
> > .Close False
> > Set Doc = Nothing
> > End With
> >
> > WinWord.Quit False
> > DoEvents
> > Set WinWord = Nothing
> > DoEvents
> >
> >
> > Hope this helps...
> > Christian
> >
> >
> > --
> > Pour répondre à ce message, utilisez EXCLUSIVEMENT ce lien :
> > http://couriel.biz/c2h/
> > ********************************************************
> >
> >
> > Bonjour,
> >
> >
> >
> >
> >
> > Cordialement
> >
> > Christian Hubert-Hugoud
> >
> > "lou" a écrit dans le message de
> > news:41a7860b$0$25044$
> > > bonjour
> > > je me serts de ce code pour travailler un fichier word
> > > apparament il fonctionne bien
> > >
> > > mais apres avoir fait plusieurs essais
> > > mon pc n'en pouvais plus et je me suis demandé pourquoi ??? apres
> avoir
> > > cherché ,
> > >
> > > je suis allé voir dans le gestionnaire des taches et la j'ai vu


des
> > > dizaines de word dans
> > > le processus , j'ai du passer par le fin de tache pour les enlever
> > >
> > > Set W_App = Nothing ne marche pas
> > > comment fermer word sans qu'il reste dans le processus
> > > je ne trouve pas la solution
> > > un petit peu d'aide svp
> > >
> > >
> > > voici le code en question
> > >
> > > Private Sub Commande95_Click()
> > > aa.Object.Application.Options.BackgroundSave = False
> > > aa.Object.Application.Options.AllowFastSave = True
> > > aa.Object.SaveAs "C:PDFTEMP.doc"
> > >
> > > Dim W_App As Object
> > > Set W_App = CreateObject("Word.Application")
> > > With W_App
> > > .Visible = False
> > > .Documents.Open ("C:PDFTEMP.doc")
> > > .Selection.HomeKey Unit:=wdStory
> > > .Selection.EndKey Unit:=wdStory, Extend:=wdExtend
> > > .Selection.Copy
> > > .ActiveDocument.Close wdDoNotSaveChanges
> > >
> > > .Quit
> > >
> > > Set W_App = Nothing
> > >
> > > End With
> > >
> > > End Sub
> > >
> > > merci de votre aide
> > >
> > >
> > >
> > >
> > >
> >
> >
>
>




Avatar
christophe-pasde
Bonjour,

Je sais pas si ça à voir mais peut-être faut il tuer la form VB
contenant le code créeant et détruisant l'instance word ?

avec un explicite set Mafeuille = nothing dans le unload ?

J'avais une persistence d'objets dans mon appli, objets créés et
détruits dans Mafeuille, en mettant set mafeuille=nothing dans le
unload, le pb a disparu.

Si ça peut vous aider.

Christophe


lou a écrit :
bonjour
je me serts de ce code pour travailler un fichier word
apparament il fonctionne bien

mais apres avoir fait plusieurs essais
mon pc n'en pouvais plus et je me suis demandé pourquoi ??? apres avoir
cherché ,

je suis allé voir dans le gestionnaire des taches et la j'ai vu des
dizaines de word dans
le processus , j'ai du passer par le fin de tache pour les enlever

Set W_App = Nothing ne marche pas
comment fermer word sans qu'il reste dans le processus
je ne trouve pas la solution
un petit peu d'aide svp


voici le code en question

Private Sub Commande95_Click()
aa.Object.Application.Options.BackgroundSave = False
aa.Object.Application.Options.AllowFastSave = True
aa.Object.SaveAs "C:PDFTEMP.doc"

Dim W_App As Object
Set W_App = CreateObject("Word.Application")
With W_App
.Visible = False
.Documents.Open ("C:PDFTEMP.doc")
.Selection.HomeKey Unit:=wdStory
.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
.Selection.Copy
.ActiveDocument.Close wdDoNotSaveChanges

.Quit

Set W_App = Nothing

End With

End Sub

merci de votre aide







1 2