Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Posts
    369
    Thanks
    2
    Thanked 1 Time in 1 Post
    I recorded a macro to add the same footer to a number of documents. The resulting code is below. The macro fails with the error "The requested member of the collection does not exist" at Line 2, and again at line 11. I tried changing AttachedTemplate to NormalTemplate, but that doesn't exist. I've confirmed that AttachedTemplate.Name is normal.dotm. Why is this failing, and how can MS get macro recording persistently wrong?

    WordBasic.ViewFooterOnly
    ActiveDocument.AttachedTemplate.BuildingBlockEntri es( _
    " Blank (Three Columns)").Insert Where:=Selection.Range, RichText:=True
    Selection.TypeText Text:="Pre-approval version dated 19/07/2009"
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=2
    ActiveDocument.AttachedTemplate.BuildingBlockEntri es("Bold Numbers"). _
    Insert Where:=Selection.Range, RichText:=True
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

    thanks

    Edited to add error message 9th August

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='Mark P' post='787221' date='02-Aug-2009 11:52']
    Code:
    	ActiveDocument.AttachedTemplate.BuildingBlockEntries( _
    		" Blank (Three Columns)").Insert Where:=Selection.Range, RichText:=True
    [/quote]
    Should there be a space at the beginning of the AutoText/BuildingBlock name?

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Mark,

    Can't test this in 2007 at the moment, but a couple of questions:

    What was the error message? - it's missing from your post.

    What user interface action did you take, that got recorded as "WordBasic.ViewFooterOnly"?

    If I try to run that single line of code, I get an "Object doesn't support this property or method" error.

    And if I try to record the action of clicking the 'View Footer' button (apparently old command dredged up from Customize), the resultant code I get is:

    Code:
       If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    	  ActiveWindow.Panes(2).Close
       End If
       If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
    	  ActivePane.View.Type = wdOutlineView Then
    	  ActiveWindow.ActivePane.View.Type = wdPrintView
       End If
    (not "WordBasic.ViewFooterOnly")

    Gary

  4. #4
    3 Star Lounger
    Join Date
    Feb 2001
    Posts
    369
    Thanks
    2
    Thanked 1 Time in 1 Post
    [quote name='jscher2000' post='787242' date='02-Aug-2009 21:45']Should there be a space at the beginning of the AutoText/BuildingBlock name?[/quote]

    Sorry, posted without proper formatting. Never quite got the hang of the lounge tags, but just being lazy. The continuation of the line is indeed indented.

  5. #5
    3 Star Lounger
    Join Date
    Feb 2001
    Posts
    369
    Thanks
    2
    Thanked 1 Time in 1 Post
    [quote name='Gary Frieder' post='787283' date='03-Aug-2009 08:23']What was the error message? - it's missing from your post.[/quote]

    Sorry, forgot to go back and add it. The error message is "The requested member of the collection does not exist"

    What user interface action did you take, that got recorded as "WordBasic.ViewFooterOnly"?
    I chose "Blank (Three Columns)" from the Insert Footer Menu on the Insert ribbon.

    I don't think there is any similar equivalent in previous versions of Word - although I've moved straight from 2000 to 2007, and am not really enjoying the experience, I have to say.

    There is no similar View Footer command in 2007 that I can see. The way that footers are dealt with is also very different. I was used to the old way with the split windows allowing me to easily left and right align text in a footer. Now it seems that the options are either to choose the three column format from the proffered styles, or do it all manually. There's a similar problem with page numbers, where the large number of different styles offered means clicking and scrolling just to add Page X of Y, or remembering the codes for manual entry. But I digress.

    Thanks for the help, but I don't think this problem is amenable to testing in previous versions of Word.

    Any more ideas?

    I

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='Mark P' post='788155' date='09-Aug-2009 06:23']Sorry, posted without proper formatting.[/quote]
    Actually, I hadn't checked the name of the "building block" and it does have a space before the word Blank.

    The problem is the template reference. Although Building Blocks.dotx has a type code of an attached template, it isn't really "the" attached template for purposes of VBA. Here is a revised procedure that gets to that template:

    Code:
    Sub SetupFooter()
    Dim bbtmp As Word.Template
    Set bbtmp = GetTemplate("Building Blocks.dotx")
    ' Footer
    WordBasic.ViewFooterOnly
    bbtmp.BuildingBlockEntries(" Blank (Three Columns)").Insert _
    	Where:=Selection.Range, RichText:=True
    Selection.TypeText Text:="Pre-approval version dated 19/07/2009"
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=2
    bbtmp.BuildingBlockEntries("Bold Numbers").Insert _
    	Where:=Selection.Range, RichText:=True
    ' Close footer
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End Sub
    
    Function GetTemplate(strName As String) As Word.Template
    Dim oTemplate As Word.Template
    For Each oTemplate In Word.Templates
    	If oTemplate.Name = strName Then
    		Set GetTemplate = oTemplate
    		Exit Function
    	End If
    Next
    End Function
    The ultimate result is not right on my Word, but it's a starting point.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •