Page X of Y error when moving info from excel to word

W

Wdd1

Hi All,
I was wondering if some one could help me. I'm trying to update an
old script that put "Page X of Y" in bottom of my word documents. The
word documents were being fed information from excel. I have this
script and it works well inside Word:

Sub Make_footer()

With Word.Application.ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = _
"C:\Program Files\Microsoft Office\Office12\Document Parts
\1033\Building Blocks.dotx"
.XMLSchemaReferences.AutomaticValidation = True
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
End With


Word.Application.WordBasic.ViewFooterOnly


Word.Application.ActiveDocument.AttachedTemplate.BuildingBlockEntries
("Bold Numbers 3").Insert Where:=Selection.Range, RichText:=True
Word.Application.ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
End Sub

Inside of word, I don't get any errors. Bold Number 3 is a built in
Block. The problem occurs when I try to use Excel to output the
information in word. See below:


Sub Create_blank_copy()
MsgBox ("Create a new blank copy")

Cells(8, 11).Value = ""
Cells(19, 14).Value = "<- Complete"
Cells(25, 11).Value = "<- Complete "
Cells(30, 11).Value = ""



'Collect study info
study_number = InputBox("What is the study number?")
study_title = InputBox("What is the title of this round?")


'Look at question sheet
Sheets("Survey Questions Template").Visible = True
Sheets("Survey Questions Template").Activate

'Open Word
Dim AppWord As Word.Application
Set AppWord = CreateObject("Word.Application")
AppWord.Visible = True
AppWord.Documents.Add

'Open Header & Footer, paste information
AppWord.ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageHeader
AppWord.Selection.TypeText Text:="Macro v2.0" & vbTab & vbTab &
CStr(Date)

'Insert page numbers
With Word.Application.ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = _
"C:\Program Files\Microsoft Office\Office12\Document Parts
\1033\Building Blocks.dotx"
.XMLSchemaReferences.AutomaticValidation = True
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
End With


Word.Application.WordBasic.ViewFooterOnly


Word.Application.ActiveDocument.AttachedTemplate.BuildingBlockEntries
("Bold Numbers 3").Insert Where:=Selection.Range, RichText:=True
Word.Application.ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
End Sub

When I run this macro I get, "Run Time Error 450: Wrong number of
arguments or invalid property assignment" on the
"Word.Application.ActiveDocument.AttachedTemplate.BuildingBlockEntries
("Bold Numbers 3").Insert Where:=Selection.Range, RichText:=True"
line. Does anyone know why or have an easier way of numbering pages?
I need the X of Y format.

Thanks!
 
G

GF

Haven't tried running your code, but it looks like the following is happening:

When you're running the code from Word, you're prefacing everything with
"Word.Application" which by the way isn't necessary - when working in Word,
the "Word.Application" is assumed.

Anyway, in the code you're running from Excel, you've set an object
reference to Word:

Set AppWord = CreateObject("Word.Application")

From that point forward, you need to consistently preface any code that
refers to Word, with "AppWord".
Instead, just a little further into the code, you start using
"Word.Application" - all of those references should be to "AppWord" instead.

hth,
GF
 

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