Question modification hyperlink dans doc

Plus d'informations
il y a 12 ans 10 mois #14785 par Richard Lazaro
Bonjour,

En PowerShell, chaque commande retourne des objets.
Get-ChildItem ne fait pas exception à la régle et retourne des DirectoryInfo et FileInfo comme objet.

Or la méthode Open attend un chemin vers un fichier et donc un objet de type String.

Pour cela il faut donc utiliser la propriété Fullname de l'objet

EDIT : et tu as oublié de mettre ta variable $collection pour récupérer les infos du Get-ChildItem ;)

[code:1]
$collection = get-childitem -path \"d:\\" -recurse -include *.docx
foreach($DocFile in $collection){
$objWord = New-Object -Com Word.Application
$objWord.Visible = $true
$objDoc = $objword.Documents.open($DocFile.FullName)
$colHyperlinks = $objDoc.Hyperlinks
Foreach($objHyperlink in $colHyperlinks){
if($objHyperlink.Address -eq \"www.microsoft.com/\"«»){
$objHyperlink.Address = \"www.microsoft.com/technet/scriptcenter/\";
}
}
$wdFormatDocument = 16 # msdn.microsoft.com/en-us/library/bb238158%28v=office.12%29.aspx
$objDoc.SaveAs([ref]$DocFile,[ref]$wdFormatDocument)
$objDoc.close()
$objWord.Quit()
}
[/code:1]

Je n'ai pas testé, juste regardé le code.

Bien Cordialement,
Richard Lazaro.

Ps : Bonjour aux autre, cela faisait un moment que je ne suis pas venu ^^<br><br>Message édité par: Richard Lazaro, à: 6/05/13 09:45

Think-MS : (Get-Life).Days | %{ Learn-More }

\\"Problems cannot be solved by the same level of thinking that created them.\\" - Albert Einstein

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 12 ans 10 mois #14786 par stas
Réponse de stas sur le sujet Re:modification hyperlink dans doc
Hello,

Voila c'est en ordre une pt modif dans le script et cela fonctionne parfaitement.

[code:1]
$collection = get-childitem -path \&quot;D:\\&quot; -recurse -include *.docx
foreach($DocFile in $collection){
$objWord = New-Object -Com Word.Application
$objWord.Visible = $true
$objDoc = $objword.Documents.open($DocFile.FullName)
$colHyperlinks = $objDoc.Hyperlinks
Foreach($objHyperlink in $colHyperlinks){
if($objHyperlink.Address -eq \&quot;www.microsoft.com/\"«»){
$objHyperlink.Address = \&quot;www.microsoft.com/technet/scriptcenter/\";
}
}
$wdFormatDocument = 16 # msdn.microsoft.com/en-us/library/bb238158%28v=office.12%29.aspx
$objDoc.SaveAs([ref]$DocFile.FullName,[ref]$wdFormatDocument)
$objDoc.close()
$objWord.Quit()
}
[/code:1]

la modif pour le saveas aussi en fullname et c'est ok

MERCI A TOUS
Peux être en RÉSOLUS

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.047 secondes
Propulsé par Kunena