Solved

Change a word bookmark by an hyperlink

Posted on 2012-04-03
2
1,134 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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