0
votes

Our departments are switching from SharePoint 2007 to 2010. The old SharePoints allowed us to use the same URL and Window title for forms, but SharePoint 2010 show the URL and Window title for a list of forms that have been filled out. On that page, there is a link called "Add new item":

enter image description here

To get to a new form, they have to click that link; which brings up a new window with its own title:

enter image description here

Here's the code I have to get to the first image:

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

Can anyone help me figure out how to set the focus for the second image titled " - New Item"? I've tried:

Set WShell = CreateObject("WScript.Shell")

WShell.AppActivate " - New Item"

Set WShell = Nothing

That doesn't work. I've tried:

Set WShell = CreateObject("WScript.Shell")

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

Set WShell = Nothing

That doesn't work either. Hopefully someone has a solution I can try.

1

1 Answers

0
votes

SharePoint 2010 uses Javascript to open a list form in a modal dialog. The actual form would be in page called newform.aspx. For example, if your list is at http://mysite.mydomain.com/lists/tasks, the new item page would be at http://mysite.mydomain.com/lists/tasks/newform.aspx.

Perhaps an easier way to d this is to use the Javascript Object Model. Microsoft includes a function called showModalDialog that would open the dialog window for you.

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

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

Then in the ribbon add

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

You can also make it more generic bu passing the url to the openNew function

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

Add New