Solved

Change a word bookmark by an hyperlink

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now