如何向我的 Mailadr 添加超链接

问题描述 投票:0回答:1

我已经创建了一个脚本来通过Word创建电子邮件签名,问题是我想为邮件地址提供带有“mailto:$email”的超链接,但我不知道该怎么做。 我尝试了很多可能性,但没有任何效果。有人可以帮助我吗?

我喜欢插入的代码:

# change all the placeholde in our Word template

$MSWord.Documents.Open("$LocalSignaturePath\$newSignatureName.docx", $false)

$FindText = "Name"
$ReplaceText = $titel.ToString() + " " + $vorname.ToString() + " " + $nachname.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,  $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll)

$FindText = "EMAIL"
$ReplaceText = $email.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,  $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll)

$FindText = "Description"
$ReplaceText = $job.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,  $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll)

$FindText = "mobile1"
$ReplaceText = $mobile.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,  $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll)

$FindText = "OFFICEPHONE1"
$ReplaceText = $phone.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,  $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll)

$FindText = "CITY"
$ReplaceText = $CITY.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,  $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll)

$FindText = "POSTALCODE"
$ReplaceText = $POSTALCODE.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,  $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll)

$FindText = "STREETADDRESS"
$ReplaceText = $STREETADDRESS.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,  $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll)

$FindText = "COMPANY"
$ReplaceText = $COMPANY.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,  $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll)


# Save Signature files in multiple extensions (needed for Outlook)
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
$path = "$LocalSignaturePath\$newSignatureName.htm"
$MSWord.ActiveDocument.SaveAs([ref]$path, [ref]$saveFormat)

$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
$path = "$LocalSignaturePath\$newSignatureName.rtf"
$MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)

$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatText");
$path = "$LocalSignaturePath\$newSignatureName.txt"
$MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat)

$MSWord.ActiveDocument.Close()
$MSWord.Quit()

我已经尝试了此网站的解决方案方法Powershell脚本查找并更改word保存文档中的超链接并创建一个新的PDF副本和此网站https://forums.powershell.org/t/adding-hyperlinks- to-word-via-powershell/624,但没有成功

powershell email signature
1个回答
0
投票

假设变量

$email
包含此电子邮件地址:

$email = '[email protected]'

然后在Word中用有效的电子邮件超链接替换占位符文本

EMAIL
的方法如下

$MSWord = New-Object -ComObject Word.Application
$MSWord.Visible = $false 

#$doc = $MSWord.Documents.Open("$LocalSignaturePath\$newSignatureName.docx", $false)
$doc = $MSWord.Documents.Open("D:\Test\test.docx", $false)


# this part is specific for replacing the EMAIL placeholder string with a hyperlink
$found = $MSWord.Selection.Find.Execute('EMAIL', $true, $true,  $false, $false, $false, $true, 1, $false, '', $true)
if ($found) {
    [void]$doc.Hyperlinks.Add($MSWord.Selection.Range, "mailto:$email", [type]::Missing, 'Send email', $email)
}

# save the document and quit Word
$doc.Close($true)
$MSWord.Quit()

# clean-up used Com objects when all done
$null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($doc)
$null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($MSWord)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
© www.soinside.com 2019 - 2024. All rights reserved.