在 Powerpoint 中连接超链接 VBA

Concatenate hyperlink in Powerpoint VBA

我正在尝试将 URL 与添加到 URL 末尾的许多不同部分(变量)连接起来。

我有一个按钮,当您单击该按钮时,它将使用当前幻灯片的幻灯片索引将您带到特定站点。

单击按钮时,我希望它转到 "google.com/p" + Slide.Index + slide.ID + ActivePresentation.fileName

我知道语法不正确,但希望您能理解 GIST。

目前我有这个代码:

Private Sub CommandButton21_Click()

    Dim projId AS Integer = 617
    Dim URL AS String = "www.google.com"
    Dim coID = "m01"
    Dim coTitle AS String = "New CC Project"
    Dim oSl As Slide
    Dim pgId



    ActivePresentation.FollowHyperlink _
    Address:="http://google.com/p" + oSl.SlideID
    NewWindow:=True, AddHistory:=True


End Sub

提前致谢

& 总是在字符串上下文中求值,而如果其中一个操作数不是字符串,+ 可能不会连接:

Private Sub CommandButton21_Click()

    Dim projId AS Integer
    Dim URL AS String = "www.google.com"
    Dim coID = "m01"
    Dim coTitle AS String = "New CC Project"
    Dim oSl As Slide
    Dim pgId
    projId = 617


    ActivePresentation.FollowHyperlink _
    Address="http://google.com/p" & oSl.SlideID
    NewWindow=True
    AddHistory=True


End Sub

这应该让你更接近:

Private Sub CommandButton21_Click()
    ' You can't assign values to variables at the same time
    ' as you DIM them; you CAN do so with Constants:
    Const projId As Integer = 617
    Const URL As String = "www.google.com"
    Const coID As String = "m01"
    Const coTitle As String = "New CC Project"
    Dim oSl As Slide
    'Dim pgId

    ' You can't just refer to oSl; you have to first tell it WHICH slide
    Set oSl = ActivePresentation.Slides(1) ' or whatever slide you want

    ActivePresentation.FollowHyperlink _
    Address:="http://google.com/p" & oSl.SlideID, _
    NewWindow:=True, _
    AddHistory:=True

End Sub

我已经解决了这个问题,查看下面的代码!

Sub CommandButton21_Click()
    Dim sl As slide
    Dim projId As Integer
    Dim coID As String
    Dim URL As String
    Dim coTitle As String
    Dim pgId
    URL = "www.google.com"
    projId = 617
    coID = "m01"
    coTitle = "New CC Project"

    Set sl = SlideShowWindows(1).View.slide

    ActivePresentation.FollowHyperlink _
    Address:=URL & projId & "&coIdent=" & coID & "&coTitle=" & coTitle & "&pgIdent=" & sl.slideId & "&pgTitle=" & sl.slideId & "&pageFileName=" & ActivePresentation.FullName & "&pageOrder=" & sl.SlideIndex, _
    NewWindow:=True, AddHistory:=True