Bonjour à tous,
J'ai crée un petit programme sur excel 2010 qui ouvre un fichier word pour y ajouter des modifs, ça marche très bien sur mon PC mais foire complètement qd mon collègue l'essaye avec excel 2000 SP3 et je ne comprend pas pourquoi!! En fait en excel 2000 il n'arrive pas à ouvrir le fichier word a modifier.
Et pour les object Library, on a activer sur les 2 version, mais moi j'ai la version 12 et mon collègue à la version 9.
Voici le code:
Aidez moi svp, merci d'avance.
J'ai crée un petit programme sur excel 2010 qui ouvre un fichier word pour y ajouter des modifs, ça marche très bien sur mon PC mais foire complètement qd mon collègue l'essaye avec excel 2000 SP3 et je ne comprend pas pourquoi!! En fait en excel 2000 il n'arrive pas à ouvrir le fichier word a modifier.
Et pour les object Library, on a activer sur les 2 version, mais moi j'ai la version 12 et mon collègue à la version 9.
Voici le code:
Code:
Sub Creer_notice_CBI() ' en projet
'necessite d'activer la reference microsoft Word xx.x Object Library
Dim Chemin1$, Dossier1$
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Dim fichierImg As Variant
Dim fichierImg1 As Variant
Dim fichierImg2 As Variant
Dim fichierImg3 As Variant
Dim fichierImg4 As Variant
Dim i As Byte
Dim x As Long
x = Range("e31").Value
Chemin1 = "D:\Notice CBI\"
Dossier1 = Range("i24")
On Error Resume Next
MkDir Chemin1 & Dossier1
'créer une instance de word
Set wordApp = CreateObject("Word.Application")
'rendre l'application Word visible (mettre false pour la cacher)
wordApp.Visible = False
'ouvrir le document Word (celui à modifier)
If Range("f26").Text = "1" Then
Set wordDoc = wordApp.Documents.Open("S:\CBV\Notices\Notice de base\Notice automatique CBI\Notices de base\Notice Francais CBI.doc")
Else
If Range("f26").Text = "2" Then
Set wordDoc = wordApp.Documents.Open("S:\CBV\Notices\Notice de base\Notice automatique CBI\Notices de base\Notice Anglais CBI.doc")
Else
If Range("f26").Text = "3" Then
Set wordDoc = wordApp.Documents.Open("S:\CBV\Notices\Notice de base\Notice automatique CBI\Notices de base\Notice Néerlandais CBI.doc")
Else
If Range("f26").Text = "4" Then
Set wordDoc = wordApp.Documents.Open("S:\CBV\Notices\Notice de base\Notice automatique CBI\Notices de base\Notice Allemand CBI.doc")
End If
End If
End If
End If
''------------------------------------------------------------
''Remplacer REALISE PAR
With wordDoc.Content.Find
.ClearFormatting
.Text = "Realisé_par*"
With .Replacement
.ClearFormatting
.Text = Range("e3").Text
End With
.Execute Replace:=wdReplaceAll
.Forward = True
.Wrap = wdFindContinue
End With
''---------------------------------------------------------------------------------------------------------------------------
''ENREGISTRER ET FERMER
Dim ouverture As Long
Dim NomFichier$, Chemin_Final$
Dim Dossier$
Dossier = Range("h24")
Chemin_Final = Chemin1 & Dossier
NomFichier = Range("e2")
wordDoc.Application.Selection.WholeStory
wordDoc.Application.Selection.Fields.Update
wordApp.ActiveDocument.Bookmarks("insertion_selection").Select
wordApp.Application.Selection.MoveUp Unit:=wdScreen, Count:=7
''wordApp.Visible = True
wordApp.ActiveDocument.SaveAs Filename:=Chemin_Final & NomFichier, _
FileFormat:=wdFormatDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
ouverture = MsgBox("La notice " & NomFichier & " a bien été créée et enregistée dans " & Chemin_Final & vbNewLine & "Voulez-vous l'ouvrir ?", vbYesNo, "Message")
If ouverture = vbYes Then
wordApp.Visible = True
''Set wordDoc = wordApp.Documents.Open(Chemin_Final & NomFichier & ".doc")
Else
wordDoc.Close
wordApp.Quit
End If
End Sub