?
Solved

Change a word bookmark by an hyperlink

Posted on 2012-04-03
2
Medium Priority
?
1,138 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
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…
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…
Suggested Courses

752 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