Vba 基于选择的设置范围
我想在电子邮件中使用一个参考号来突出显示并替换为指向网页的直接链接 当前代码将把新的超链接放置在电子邮件的开头,而不是选定的区域(当前Vba 基于选择的设置范围,vba,hyperlink,outlook,Vba,Hyperlink,Outlook,我想在电子邮件中使用一个参考号来突出显示并替换为指向网页的直接链接 当前代码将把新的超链接放置在电子邮件的开头,而不是选定的区域(当前wddoc.Range(0,0)) 如果我使用选择,则表示用户未定义变量 Sub AddHyperlink() Dim olEmail As Outlook.MailItem Dim olInsp As Outlook.Inspector Dim wdDoc As Object Dim oLink As Object Dim oRng As Object Dim
wddoc.Range(0,0)
)
如果我使用选择
,则表示用户未定义变量
Sub AddHyperlink()
Dim olEmail As Outlook.MailItem
Dim olInsp As Outlook.Inspector
Dim wdDoc As Object
Dim oLink As Object
Dim oRng As Object
Dim strLink As String
Dim strLinkText As String
Dim OutApp As Object
Dim OutMail As Object
Dim strText As String
On Error Resume Next
'Get Outlook if it's running
Set OutApp = GetObject(, "Outlook.Application")
'Outlook wasn't running, so cancel
If Err <> 0 Then
MsgBox "Outlook is not running so nothing can be selected!"
GoTo lbl_Exit
End If
On Error GoTo 0
Set OutMail = OutApp.ActiveExplorer.Selection.Item(1)
With OutMail
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
strText = wdDoc.Application.Selection.Range.Text
End With
strLink = "http://website.com/#" & strText & "" ' the link address
strLinkText = "" & strText & "" ' the link display text
On Error Resume Next
Set olEmail = ActiveInspector.CurrentItem
With olEmail
.BodyFormat = olFormatHTML
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range(0, 0) '!!!Cannot find something that replaces range with current selection!!!!
oRng.Collapse 0
Set oLink = wdDoc.Hyperlinks.Add(Anchor:=oRng, _
Address:=strLink, _
SubAddress:="", _
ScreenTip:="", _
TextToDisplay:=strLinkText)
Set oRng = oLink.Range
oRng.Collapse 0
.Display
End With
lbl_Exit:
Exit Sub
End Sub
子添加超链接()
以Outlook.MailItem的形式发送邮件
将SP设置为Outlook.Inspector
Dim wdDoc作为对象
作为对象的Dim-oLink
作为物体的暗角
作为字符串的暗淡strLink
将strLinkText设置为字符串
Dim OutApp作为对象
将邮件变暗为对象
将strText设置为字符串
出错时继续下一步
'如果Outlook正在运行,则获取它
Set-OutApp=GetObject(,“Outlook.Application”)
'Outlook未运行,因此取消
如果错误为0,则
MsgBox“Outlook未运行,因此无法选择任何内容!”
转到lbl_出口
如果结束
错误转到0
设置OutMail=OutApp.ActiveExplorer.Selection.Item(1)
发邮件
设置olInsp=.GetInspector
设置wdDoc=olInsp.WordEditor
strText=wdDoc.Application.Selection.Range.Text
以
strLink=”http://website.com/#&strText&“链接地址”
strLinkText=“&strText&”“”链接显示文本
出错时继续下一步
设置olEmail=ActiveInspector.CurrentItem
用电子邮件
.BodyFormat=olFormatHTML
设置olInsp=.GetInspector
设置wdDoc=olInsp.WordEditor
设置oRng=wdDoc.Range(0,0)“!!!找不到用当前选择替换范围的内容!!!!
突然崩溃0
设置oLink=wdDoc.Hyperlinks.Add(锚点:=oRng_
地址:=strLink_
子地址:=“”_
屏幕提示:=“”_
TextToDisplay:=strLinkText)
设置oRng=oLink.范围
突然崩溃0
.展示
以
lbl_出口:
出口接头
端接头
当我在MS Outlook中打开新电子邮件时,我将使用键盘快捷键设置在Outlook中的VBA中运行代码。Outlook VBA使用时,请尝试以下操作
Option Explicit
Public Sub Example()
Dim wdDoc As Word.Document
Dim rngSel As Word.selection
If Application.ActiveInspector.EditorType = olEditorWord Then
Set wdDoc = Application.ActiveInspector.WordEditor ' use WordEditor
Set rngSel = wdDoc.Windows(1).selection ' Current selection
wdDoc.Hyperlinks.Add rngSel.Range, _
Address:="U:\plot.log", TextToDisplay:="Here is the link"
End If
Set wdDoc = Nothing
End Sub
使用Outlook vba时,请尝试以下操作
Option Explicit
Public Sub Example()
Dim wdDoc As Word.Document
Dim rngSel As Word.selection
If Application.ActiveInspector.EditorType = olEditorWord Then
Set wdDoc = Application.ActiveInspector.WordEditor ' use WordEditor
Set rngSel = wdDoc.Windows(1).selection ' Current selection
wdDoc.Hyperlinks.Add rngSel.Range, _
Address:="U:\plot.log", TextToDisplay:="Here is the link"
End If
Set wdDoc = Nothing
End Sub
您从何处运行代码?当我在ms outlook中打开新电子邮件时,我将在outlook中的VBA中使用键盘schortcut设置运行代码。您从何处运行代码?当我在ms outlook中打开新电子邮件时,我将有一个键盘schortcut设置来运行outlook中VBA中的代码。这将是用“?@dripdrop”替换第一个“结束”之后的所有内容。这是完整的代码,请尝试-让我知道更改的word.document和word.selection,因为它们给我outlook.inspector和outlook.selection带来了错误。现在我在“使用WordEditor”上遇到一个不匹配错误。这将是用“?@dripdrop”替换第一个“end”之后的所有内容。这是完整的代码,请尝试-让我知道更改的word.document和word.selection,因为他们给我outlook.inspector和outlook.selection的错误。现在,我在“使用WordEditor”上遇到一个不匹配错误。