Bonjour, j’ai écrit ces 2 petits programmes VBA Word dans 2 documents différents (voir ci-dessous).
Sur chaque document Word, il y a 2 images et un bouton de commande. En cliquant sur une image, j’affiche un site WEB correspondant . En cliquant sur le bouton de commande, j’appelle l’autre document : c’est tout.
Chaque document peut appeler l’autre. Le problème que je rencontre, est qu’une nouvelle instance d’Internet est créée à chaque fois que je clique sur un document pour charger l’autre, même avec le test fait avec GetObject !!! Je ne comprends pas ! Je souhaiterais qu’une seule instance soit créée par le premier document uniquement, et que tous les autres affichages utilisent cette instance.
Pouvez-vous m’expliquer pourquoi ?
Merci beaucoup
------- Premier document Word nommé « Test affichage WEB-QDS.doc »
------- Deuxième document Word nommé « Test affichage WEB-SOP.doc »
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 Dim objIE As Object Private Sub Document_Open() On Error Resume Next Set objIE = GetObject(,"InternetExplorer.Application") If Err.Number <> 0 then Set objIE = CreateObject("InternetExplorer.Application") End If End Sub Sub Image1_Click() objIE.Navigate "http://www.caisse-epargne.fr/asp/modele1.aspx?mc=545" objIE.Visible = True End Sub Private Sub Image11_Click() objIE.Navigate "http://fr.yahoo.com/" objIE.Visible = True End Sub Private Sub CommandButton1_Click() ChangeFileOpenDirectory "D:\" Documents.Open FileName:="""Test affichage WEB-SOP.doc""", _ ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _ PasswordDocument:="", PasswordTemplate:="", Revert:=False, _ WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _ wdOpenFormatAuto, XMLTransform:="" End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 Dim objIE As Object Private Sub Document_Open() On Error Resume Next Set objIE = GetObject(,"InternetExplorer.Application") If Err.Number <> 0 then Set objIE = CreateObject("InternetExplorer.Application") End If End Sub Sub Image1_Click() objIE.Navigate "http://www.google.fr/" objIE.Visible = True End Sub Private Sub Image11_Click() objIE.Navigate "http://www.mappy.fr/" objIE.Visible = True End Sub Private Sub CommandButton1_Click() ChangeFileOpenDirectory "D:\" Documents.Open FileName:="""Test affichage WEB-QDS.doc""", _ ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _ PasswordDocument:="", PasswordTemplate:="", Revert:=False, _ WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _ wdOpenFormatAuto, XMLTransform:="" End Sub
Partager