VB runtime error 5941 Help

M

maviso5

Hello

I have created a macro that puts my name and the date in the header when i
push the assigned keys Ctrl + D. However when i run the macro this is what
the VB error takes me to:

'
' Macro2 Macro
'
'
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
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
ActiveDocument.AttachedTemplate.BuildingBlockEntries("
Blank").Insert _
Where:=Selection.Range, RichText:=True

Selection.TypeText Text:="Daniel Davey 13NB" & vbTab & vbTab
Selection.InsertDateTime DateTimeFormat:="dd/MM/yyyy",
InsertAsField:=True _
, DateLanguage:=wdEnglishUK, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub


This bit...

ActiveDocument.AttachedTemplate.BuildingBlockEntries("
Blank").Insert _
Where:=Selection.Range, RichText:=True


Is the bit that it doesnt like....can anyone help me?


Dan
 
D

Doug Robbins - Word MVP

Is that piece of code on two lines or three? It appears three in your post,
but the first line does not have a visual basic line feed character at the
end of it.

However, you can do the whole thing with just

Selection.Sections(1).Headers(wdHeaderFooterPrimary).Range _
.Text = "Daniel Davey 13NB" & vbTab & vbTab & _
Format(Date, "dd/MM/yyyy")


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Suzanne S. Barnhill

Do you really need a macro? Why not just use an AutoText entry? It can
include a DATE or CREATEDATE field along with your name. You can assign it
to Ctrl+D if you like.
 
B

Beth Melton

You can create a Building Block for this purpose and add it to the Header
gallery instead of using a macro to insert a Building Block and add
additional text.

All you need to do is create your header, select it, on the contextual
Header & Footer tools design tab, click Header, and then click "Save
selection to Header gallery". To make sure it displays at the top of the
gallery, in the Create New Building Block dialog box, create a new category
that starts with a space or symbol. Then to insert your header, on the
Insert tab click Header and then click your Building Block.

~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP
https://mvp.support.microsoft.com/profile/Melton
What is a Microsoft MVP? http://mvp.support.microsoft.com/gp/mvpfaqs

Guides for the Office 2007 Interface:
http://office.microsoft.com/en-us/training/HA102295841033.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top