aaliyan
Messages postés104Date d'inscriptionsamedi 12 mars 2005StatutMembreDernière intervention30 avril 2007
-
26 avril 2007 à 09:52
cs_MPi
Messages postés3877Date d'inscriptionmardi 19 mars 2002StatutMembreDernière intervention17 août 2018
-
26 avril 2007 à 23:13
Bonjour,
j'ai un problème de selection avec word sous une macro de ACCESS.
En fait je fais des selections sous un doc word, grâce à des signets.
Mais lorsque ma selection est vide, c'est à dire que rien n'a été écrit dans le doc word.
Et lorsque cette selection est vide, je voudrais faire un if, end if.
Le code pour mieux comprendre:
If Wd.ActiveDocument.Bookmarks.Exists("dcréa") = True Then
Wd.ActiveDocument.Bookmarks("dcréa").Select
End If
'Pour affiner la selection sur une seule ligne
Call Wd.Selection.MoveDown(wdLine, 1, wdExtend)
Call Wd.Selection.MoveLeft(wdCharacter, 4, wdExtend)
If Wd.Selection <> "" Then
Wd.Selection.Copy
d1 = Wd.Selection
End If
If Wd.ActiveDocument.Bookmarks.Exists("dmaj") = True Then
Wd.ActiveDocument.Bookmarks("dmaj").Select
End If
'Pour affiner la selection sur une seule ligne
Call Wd.Selection.MoveDown(wdLine, 1, wdExtend)
Call Wd.Selection.MoveLeft(wdCharacter, 3, wdExtend)
If Wd.Selection <> "" Then
Wd.Selection.Copy
dmaj = Wd.Selection
End If
En fait le "If Wd.Selection <> "" Then" ne fonctionne pas, j'ai essayé un IsNull(Wd.Selection),
Wd.Selection <> vide.
aaliyan
Messages postés104Date d'inscriptionsamedi 12 mars 2005StatutMembreDernière intervention30 avril 2007 26 avril 2007 à 15:01
Après plus d'une heure de recherche intensive, j'ai finit par trouver la solution :
If Wd.ActiveDocument.Bookmarks.Exists("dmaj") = True Then
Wd.ActiveDocument.Bookmarks("dmaj").Select
End If
Call Wd.Selection.MoveDown(wdLine, 1, wdExtend)
Call Wd.Selection.MoveLeft(wdCharacter, 3, wdExtend)
dmaj = Wd.Selection
'Si dmaj est une date sinon null
If IsDate(dmaj) = False Then
dmaj = "Null"
End If
Comme c'est une date, je teste son format.
Si ce n'était pas une date, il aurait fallu mettre :
If Asc(Trim(dmaj)) = vbCrLf Then
dmaj = ""
End If
aaliyan
Messages postés104Date d'inscriptionsamedi 12 mars 2005StatutMembreDernière intervention30 avril 2007 26 avril 2007 à 10:40
En fait ça marche pas parce que vbnullstring = "", et comme je n'ai pas de texte dans ma ligne, je n'ai rien du tout selectionné. Ce n'est pas égale à "".
Ce qu'il me faudrait c'est savoir si le premier caractère est égale à "". Je fais donc ça :
If Wd.ActiveDocument.Bookmarks.Exists("dmaj") = True Then
Wd.ActiveDocument.Bookmarks("dmaj").Select
End If
Call Wd.Selection.MoveRight(wdCharacter, 1, wdExtend)
If Wd.Selection <> vbNullString Then
Call Wd.Selection.MoveDown(wdLine, 1, wdExtend)
Call Wd.Selection.MoveLeft(wdCharacter, 3, wdExtend)
Wd.Selection.Copy
dmaj = Wd.Selection
End If
Le truc, c'est comme je suis dans un tableau et que ma ligen est vide, cela me selectionne la ligne du tableau et non un seul caractère, ce qui rend le Call Wd.Selection.MoveRight(wdCharacter, 1, wdExtend)
If Wd.Selection <> vbNullString Then
inefficace.
aaliyan
Messages postés104Date d'inscriptionsamedi 12 mars 2005StatutMembreDernière intervention30 avril 2007 26 avril 2007 à 10:59
En fait quand j'ai rien dans mon tableau, j'arrive à récupérer la ligne entière du tableau.
Il n'y a aucun caractère à l'intèrieur de la ligne.
Voilà ce que j'ai
Date<?xml:namespace prefix o ns "urn:schemas-microsoft-com:office:office" /??>
aaliyan
Messages postés104Date d'inscriptionsamedi 12 mars 2005StatutMembreDernière intervention30 avril 2007 26 avril 2007 à 11:23
Pour répondre à ta question :
Donc quand il y a rien dans ton tableau tu as un caractère de substitution qui est " ", et c'est cela que tu veux récupèrer ?
aaliyan
Messages postés104Date d'inscriptionsamedi 12 mars 2005StatutMembreDernière intervention30 avril 2007 26 avril 2007 à 11:25
Voilà le caractère que j'ai lorsque il n'y a rien dans ma ligne, mais je n'arrive pas à le tester.
Les caractères sont en copier coller grâce à un espion :