Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

New Section Footer via Automation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AG - 20 Sep 2007 21:08 GMT
I am using automation from Access 2000 to create a new Word doc (2000-2003).
The doc consists of several sections with tables and footers. I can generate
and fill all data, text, etc with no problem on my machine and generate a
completed doc as desired.
However, on client's machine, the separate section footers do not behave as
desired.
Instead of creating a new footer, the previous footer is being modified with
the content intended for the new footer.

Here is a sniplet of code that I am using to add the new footer.
Yes, all objects are properly defined/instantiated. No errors are generated.

   Selection.EndKey Unit:=wdStory
   Selection.InsertBreak Type:=wdSectionBreakNextPage
  mappWord.Visible = True
  Selection.EndKey Unit:=wdStory    '9/20/2007
  If docWord.ActiveWindow.View.SplitSpecial <> wdPaneNone Then
     docWord.ActiveWindow.Panes(2).Close
  End If
  If docWord.ActiveWindow.ActivePane.View.Type = wdNormalView _
  Or docWord.ActiveWindow.ActivePane.View.Type = wdOutlineView Then
     docWord.ActiveWindow.ActivePane.View.Type = wdPrintView
  End If

  docWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
  If Selection.HeaderFooter.IsHeader = True Then
     docWord.ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
  End If
  Selection.HeaderFooter.LinkToPrevious = False
  On Error Resume Next
'I think the problem is related to this line. Client was generating error
'command not avaliable..' here
while I was not. Yet, I had similar footer problem without this line.
   docWord.ActiveWindow.ActivePane.View.NextHeaderFooter
  On Error GoTo ErrLine
  Selection.WholeStory
  Selection.Delete Unit:=wdCharacter, Count:=1
  Selection.HeaderFooter.PageNumbers.Add PageNumberAlignment:= _
     wdAlignPageNumberRight, FirstPage:=True
  Selection.MoveLeft Unit:=wdCharacter, Count:=1
   'do some formatting, type text etc. for footer

I am guessing that it is related to some option setting on client's machine.

Any help would be appreciated.
Signature


AG
Email: discussATadhdataDOTcom

Tony Strazzeri - 21 Sep 2007 01:08 GMT
> I am using automation from Access 2000 to create a new Word doc (2000-2003).
> The doc consists of several sections with tables and footers. I can generate
[quoted text clipped - 46 lines]
> AG
> Email: discussATadhdataDOTcom
The command not available at thayt point suggests that the selection
has come out of the footer/header and dropped back to the Main
document story.

Also have a look at the starting view that you use v your clients.  ie
are you both running the macro from Normal view or Print Layout view.

Hope this helps

Cheers
TonyS.
AG - 21 Sep 2007 02:41 GMT
Thanks Tony,

I will rewrite the section where the view is checked. As Jay pointed out it
comes from recorder code and I did not look at it close enough. It only
checks for normal or outline view, but maybe this user has a different
'default' view.

Signature

AG
Email: discussATadhdataDOTcom

>> I am using automation from Access 2000 to create a new Word doc
>> (2000-2003).
[quoted text clipped - 64 lines]
> Cheers
> TonyS.
Jay Freedman - 21 Sep 2007 01:35 GMT
I hate to be the bearer of bad news, but that code is horrible, the
sort of stuff you get out of the macro recorder because it doesn't
know any better. (See
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm for a
critique of that garbage grinder.)

Instead of writing a macro that pushes the Selection around and works
as if an automaton was pressing keys, use the objects that VBA makes
available. Something like this:

Sub NewSectionFooter()
   Dim docWord As Word.Document
   Dim wSection As Word.Section
   Dim wRange As Word.Range
   
   Set docWord = ActiveDocument  ' or = Word.Documents.Add
   Set wRange = docWord.Range
   wRange.Collapse wdCollapseEnd
   wRange.InsertBreak Type:=wdSectionBreakNextPage
   
   ' since the break is inserted before wRange,
   ' wRange is contained in the new section, so
   ' the new section is wRange.Sections(1)
   Set wSection = wRange.Sections(1)
   With wSection.Footers(wdHeaderFooterPrimary)
       .LinkToPrevious = False
       .Range.Text = "some text here"  ' replaces whatever was there
       .PageNumbers.Add PageNumberAlignment:= _
           wdAlignPageNumberRight, FirstPage:=True
   End With
End Sub

Please ask questions if there's any part of that macro that's unclear
to you.

>I am using automation from Access 2000 to create a new Word doc (2000-2003).
>The doc consists of several sections with tables and footers. I can generate
[quoted text clipped - 42 lines]
>
>Any help would be appreciated.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
AG - 21 Sep 2007 02:48 GMT
Thanks Jay,

Your points are well taken. Yes, I admit the code came from the recorder
with just a bit of tweaking. Not my usual style, but I do very little Word
VBA and find the documentation woefully lacking. My usual is VB, Access VBA
and .NET.
Good article also, which I do agree with. Although, I do tend to leave in a
lot of the garbage, just so I can later go back and tweak a few other
properties without having to spend a lot of time figuring out how to access
them.
I will try your method tomorrow.

Signature

AG
Email: discussATadhdataDOTcom

>I hate to be the bearer of bad news, but that code is horrible, the
> sort of stuff you get out of the macro recorder because it doesn't
[quoted text clipped - 90 lines]
> Email cannot be acknowledged; please post all follow-ups to the newsgroup
> so all may benefit.
AG - 27 Sep 2007 13:42 GMT
Jay,

Just wanted to say thanks. Your approach solved the problem, along with
another that popped up.

Signature

AG
Email: discussATadhdataDOTcom

>I hate to be the bearer of bad news, but that code is horrible, the
> sort of stuff you get out of the macro recorder because it doesn't
[quoted text clipped - 90 lines]
> Email cannot be acknowledged; please post all follow-ups to the newsgroup
> so all may benefit.
Jay Freedman - 27 Sep 2007 14:53 GMT
You're welcome! That's why I'm here.

Jay

> Jay,
>
[quoted text clipped - 97 lines]
>> Email cannot be acknowledged; please post all follow-ups to the
>> newsgroup so all may benefit.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.