2014-11-06 23 views
0

我們的部門正在從SharePoint 2007切換到2010年。舊SharePoint允許我們爲表單使用相同的URL和Window標題,但SharePoint 2010顯示列表的URL和Window標題已填寫的表格。在該頁面中,有一個名爲「添加新項目」鏈接:vbscript訪問Sharepoint 2010表單以輸入收集到的數據

enter image description here

要進入一個新的形式,他們必須單擊鏈接;這與它自己的標題會彈出一個新窗口:

enter image description here

這裏是我去的第一個圖像的代碼:

URL = "http://myURL.com/AllItems.aspx" 
Window = " - All Tasks" 
URLFound = False 

Set objShell = CreateObject("Shell.Application") 
Set objShellWindows = objShell.Windows 

For Each objIE In objShell.Windows 
Next 

For i = 0 to objShellWindows.Count - 1 
    Set objIE = objShellWindows.Item(i) 
    On Error Resume Next 
    If InStr(UCase(objShellWindows.Item(i).LocationURL), UCase(URL)) Then 
    If InStr(UCase(objShellWindwos.Item(i).FullName), "IEXPLORE.EXE") Then 
     If Err.Number = 0 Then 
     If InStr(objShellWindows.Item(i).Document.Title, (Window)) Then 
      URLFound = True 
      Exit For 
     End If 
     End If 
    End If 
    End If 
Next 

objIE.Visible = True 

objIE.Document.All.Item("idAddNewItemLink").Click 

Set objShell = Nothing 
Set objShellWindows = Nothing 
Set objIE = Nothing 

誰能幫助我弄清楚如何設置焦點第二張圖片名爲「 - New Item」?我試過了:

Set WShell = CreateObject("WScript.Shell") 

WShell.AppActivate " - New Item" 

Set WShell = Nothing 

這是行不通的。我試過了:

Set WShell = CreateObject("WScript.Shell") 

If objIE.Document.Title = " - All Tasks" Then 
    WShell.AppActivate " - New Item" 
End If 

Set WShell = Nothing 

這也行不通。希望有人有我可以嘗試的解決方案。

回答

0

SharePoint 2010使用Javascript在模態對話框中打開列表表單。實際的表單將在頁面中調用newform.aspx。例如,如果您的清單是http://mysite.mydomain.com/lists/tasks,則新項目頁面將在http://mysite.mydomain.com/lists/tasks/newform.aspx

也許更簡單的方法是使用Javascript對象模型。 Microsoft包含一個名爲showModalDialog的函數,可以爲您打開對話窗口。

function openNew() { 
    var options = { 
    title: "New Item", 
    url: "/path/to/your/list/NewForm.aspx" 
    }; 

    SP.UI.ModalDialog.showModalDialog(options); 
} 

然後在功能區中添加

<a onclick="openNew();return false;" href="#">Add New</a> 

您也可以使它更通用的BU傳遞的URL openNew功能

function openNew(url) { 
    var options = { 
    url: url, 
    title: "New Item" 
    } 
    SP.UI.ModalDialog.showModalDialog(options); 
} 

添加新

+0

所以我會將我的代碼的第一部分複製到列表中,並調用表單的URL和Window標題? – Lou 2014-11-06 21:32:00

+0

如果我明白你在做什麼,那麼是的。 – Robbert 2014-11-06 21:40:09

+0

我想'如果InStr(UCase(objShellWindows.Item(i).LocationURL),UCase(URL))然後'然後程序停止。我複製並粘貼了上面的所有內容,除了我更改了URL和Window之外,它只是停止了。有任何想法嗎? – Lou 2014-11-07 15:02:44