2015-05-19 156 views
0

我想连接一个带有许多不同部分(变量)的URL,并将其添加到URL的末尾。Powerpoint VBA中的连接超链接

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

当按钮是点击我要它去“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 

感谢

回答

2

这应该会让你更接近一点:

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 
+0

谢谢!有效!!! – dHumphrey

+0

不错的工作伙伴;) – moffeltje

1

&总是在字符串上下文中计算的,而+可能不串联,如果一个操作数是没有字符串:

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 
+0

为什么我会得到一个错误的'昏暗PROJID为整数= 617'和'NewWindow:=真,AddHistory:= TRUE; – dHumphrey

+0

看到更新的答案 – moffeltje

0

我修复了这个问题,查看下面的代码!

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