Solved

Change a word bookmark by an hyperlink

Posted on 2012-04-03
2
1,133 Views
Last Modified: 2012-04-03
Hi, I am pretty new in powershell scripting so I am asking for your help.

I created a simple word file in path c:\tmp\test.rtf
Inside this file, I created a bookmark name link.

With this code I change the bookmark by my email address:

$MSWord = New-Object -com word.application
$objDoc = $MSWord.Documents.Open('c:\tmp\test.rtf')
$MSWord.Visible = $true
$email= "my@email.com"
($MSWord.ActiveDocument.Bookmarks.Item("link")).Select()
$MSWord.Selection.text = $email

With that code I can add an hyperlink to my test.rtf file:

$MSWord = New-Object -com Word.Application
$objDoc = $MSWord.Documents.Open('c:\tmp\test.rtf')
$MSWord.Visible = $true
$objRange = $objDoc.Range()
$email= "my@email.com"
$objLink = $objDoc.HyperLinks.Add($objRange, $email,$null,$null,$email)

Here what I am looking for:
I want to replace my bookmark by an hyperlink and I did not succeed in mixing those two script.

Your help would really be appreciated.
0
Comment
Question by:Digico
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 37803130
I don't know Powershell, but this is an attempt to translate from the way that it could be done in VBA
$MSWord = New-Object -com Word.Application
$objDoc = $MSWord.Documents.Open('c:\tmp\test.rtf')
$MSWord.Visible = $true
$objRange = $objDoc.Bookmarks.Item("link")).Range
$email= "my@email.com"
$objLink = $objDoc.HyperLinks.Add($objRange, $email,$null,$null,$email)

Open in new window

0
 
LVL 3

Author Closing Comment

by:Digico
ID: 37803217
It worked!

Only thing i needed to add was in line 6:
$objLink = $objDoc.HyperLinks.Add($objRange, “mailto:” + $email,$null,$null,$email)
That way the email link to my email address and not to a local file.

Thank you very much for your help!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question