我是MS Publisher 2010的新手,我正在尝试添加一个"动态"引用特定页面。理想情况下,可视化文本应该是这样的:
...see the example on page XXX
我想让XXX部分可视化我所指的页面的页码。我看到你可以在文档中放置书签,并创建指向那些书签的超链接,但到目前为止,我无法看到与书签相关联的页码。
再举一个例子,我想要相当于这个Latex表达式:
...see the example on page~\pageref{reference-to-XXX}
是否可以在Publisher 2010中获得此效果,可能使用VB脚本?谢谢你的帮助!
答案 0 :(得分:1)
“这对于Pub 2007来说相当容易。只需插入>书签并将该图标拖动到您想要链接的位置。然后选择文本>插入超链接>放置在此文档中并选择您的书签我刚遇到问题的唯一一次是页面在书签下方的时间不长......并且有解决方法。 http://office.microsoft.com/en-us/publisher-help/create-a-hyperlink-HP010203490.aspx DavidF“
如果这有帮助,或者由于某种原因需要在VBA中进行,请告诉我
编辑: 编写宏来刷新页面链接相当容易,但是对象模型似乎很难支持书签链接,除非我忽略了某些东西。我的解决方案由两部分组成。
首先,应该刷新的链接由以“page”开头的显示文本识别(LIKE“page *”)。刷新宏只是识别这些链接并将其显示文本更改为页面X.但是,这不适用于书签的链接,书签中的书签似乎表现得像页面的链接,除了它们引用的pageID不存在。我花了很长时间试图找出这个不存在的超链接和书签之间的关系,但无济于事。相反,我创建了一个解决方法,在其中您使用标记对象手动链接超链接和书签(使用超链接的不存在的页面ID的值为书签创建标记)。
指向页面的常规链接的说明
创建指向页面的超链接。它的文本必须以“页面”开头 (否则必须编辑RefreshReferenceLinks)
运行C_RefreshReferenceLinks进行刷新以检查其是否有效
指向书签的链接说明(标记解决方法)
创建书签(插入 - >书签)
创建指向书签的超链接
选择超链接并运行A_GetPageIdOfHyperlink
选择书签并运行B_TagBookmarkWithPageId
运行C_RefreshReferenceLinks进行刷新以检查其是否有效
您可以下载我的示例项目,其中包含示例内容,说明和下面的宏:http://www.filedropper.com/showdownload.php/pageandbookmarklinks(它可能会给您一个安全警告,因为它包含宏)
完整来源
Public Const tagName = "BookmarkPageId"
Sub A_GetPageIdOfHyperlink()
Dim oHyperlink As Hyperlink
Set oHyperlink = ActiveDocument.Selection.TextRange.Hyperlinks(1)
CopyText oHyperlink.pageId
MsgBox oHyperlink.pageId & " copied to clipboard as text"
End Sub
Sub B_TagBookmarkWithPageId()
Dim oShape As Shape
Set oShape = ActiveDocument.Selection.ShapeRange(1)
If IsBookmark(oShape) Then
If TagExists(oShape.Tags, tagName) Then
oShape.Tags(tagName).Delete
End If
Dim txt As String
txt = Trim(GetClipBoardText())
Debug.Print "Ssdsd:" & txt
Dim newTag As Tag
Set newTag = oShape.Tags.Add(tagName, txt)
MsgBox "Tagged as " & tagName & " = '" & txt & "'"
Else
MsgBox "Not a bookmark"
End If
End Sub
Sub C_RefreshReferenceLinks()
Dim oPage As Page
Dim oShape As Shape
For Each oPage In ActiveDocument.Pages
For Each oShape In oPage.Shapes
RefreshInShape oShape
Next oShape
Next oPage
For Each oPage In ActiveDocument.MasterPages
For Each oShape In oPage.Shapes
RefreshInShape oShape
Next oShape
Next oPage
For Each oShape In ActiveDocument.ScratchArea.Shapes
RefreshInShape oShape
Next oShape
End Sub
Function RefreshInShape(oShape As Shape)
Dim cHyperlinks As Hyperlinks
Dim oHyperlink As Hyperlink
If oShape.HasTextFrame = False Then Exit Function
Set cHyperlinks = oShape.TextFrame.TextRange.Hyperlinks
For i = 1 To cHyperlinks.Count
Set oHyperlink = cHyperlinks(i)
If oHyperlink.TargetType = pbHlinkTargetTypePageID Then
If oHyperlink.TextToDisplay Like "page *" Then
oHyperlink.TextToDisplay = "page " & GetPageNumberByPageId(oHyperlink.pageId)
End If
End If
Next i
End Function
Function GetPageNumberByPageId(pageId)
Dim oPage As Page
Dim oShape As Shape
Dim oTag As Tag
For Each oPage In ActiveDocument.Pages
If CLng(oPage.pageId) = CLng(pageId) Then
GetPageNumberByPageId = oPage.PageNumber
Exit Function
End If
Next oPage
For Each oPage In ActiveDocument.Pages
For Each oShape In oPage.Shapes
If TagExists(oShape.Tags, tagName) Then
Set oTag = oShape.Tags(tagName)
If CStr(oTag.Value) = CStr(pageId) Then
GetPageNumberByPageId = oPage.PageNumber
Exit Function
End If
End If
Next oShape
Next oPage
GetPageNumberByPageId = "[ERROR]"
End Function
Function IsBookmark(oShape As Shape)
IsBookmark = False
If oShape.Type = pbWebHTMLFragment And oShape.AutoShapeType = msoShapeMixed Then
IsBookmark = True
End If
End Function
Function TagExists(collection As Tags, itemName As String) As Boolean
TagExists = False
Dim oTag As Tag
For Each oTag In collection
If oTag.Name = itemName Then
TagExists = True
Exit For
End If
Next oTag
End Function
Function GetParentOfType(obj As Object, sTypeName As String)
Do Until TypeName(GetParentOfType) = "Page"
Set GetParentOfType = obj.Parent
Loop
End Function
Sub CopyText(Text As String)
'VBA Macro using late binding to copy text to clipboard.
'By Justin Kay, 8/15/2014
'Thanks to http://akihitoyamashiro.com/en/VBA/LateBindingDataObject.htm
Set MSForms_DataObject = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
MSForms_DataObject.SetText Text
MSForms_DataObject.PutInClipboard
Set MSForms_DataObject = Nothing
End Sub
Function GetClipBoardText() As String
Set DataObj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
On Error GoTo Whoa
'~~> Get data from the clipboard.
DataObj.GetFromClipboard
'~~> Get clipboard contents
GetClipBoardText = DataObj.GetText(1)
Exit Function
Whoa:
GetClipBoardText = ""
End Function