In document level you have to begin and end the transactions, so in this case just a few tweaks to make this work as a Document Level Macro :
Imports:
Code:
Imports Autodesk.Revit.Creation
Imports Autodesk.Revit.Symbols
Imports Autodesk.Revit.Elements
Code:
Private Sub MakeNewSheet(ByVal strSheetNumber As String, ByVal strSheetName As String)
Me.ActiveDocument.BeginTransaction()
Dim CurrentFamily As FamilySymbolSet = Me.ActiveDocument.TitleBlocks
Dim p_Titleblock As FamilySymbol = Nothing
For Each f As FamilySymbol In CurrentFamily
If f IsNot Nothing Then
p_Titleblock = f
Exit For
End If
Next
Dim myDetailSheet As ViewSheet = Me.ActiveDocument.Create.NewViewSheet(p_Titleblock)
myDetailSheet.Name = strSheetName
myDetailSheet.SheetNumber = strSheetNumber
Me.ActiveDocument.EndTransaction()
End Sub
Calling the SUB:
Code:
Public Sub AddNewSheet()
MakeNewSheet("A2.01", "First Floor Plan")
MakeNewSheet("A2.02", "Second Floor Plan")
End Sub
of course you may want to wrap this bad boy in some Try-Catching if ya know what I mean!