Solved

For martynjpearson: SetDifferentFirstPageHeaderFooter...why do I get run error ??

Posted on 2003-11-24
9
340 Views
Last Modified: 2013-11-20
martyn,

Appreciate your help here again....here is my code so far for header with logo that is to be displayed on first page only:
                  COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
                  //Creates new doc
                  Documents documents = application.GetDocuments();
                  _Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty);
            Selection selection(application.GetSelection());

                  Window oWin = application.GetActiveWindow();
                  Pane oPane = oWin.GetActivePane();
                  View oView = oPane.GetView();
                  oView.SetSeekView(wdSeekCurrentPageHeader);
                  //since a doc has already been opened, just find the active one
                  _Document oDocument = application.GetActiveDocument();//
                  PageSetup oPageSetup = oDocument.GetPageSetup();
                  //This initializes oPageSetup properly
                  oPageSetup.SetDifferentFirstPageHeaderFooter(1);                   
                  Selection oSel = application.GetSelection();
                  Shapes oShapes = oSel.GetInlineShapes();
                  oShapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
  //**********************************

This all compiles fine, but I get a run error from the following line:
oPageSetup.SetDifferentFirstPageHeaderFooter(1);

it tells me the parameter in incorrect: Why is this so...and can you help me out on this please ? I've got to get this working for next monday. Thanks.
Bruce
0
Comment
Question by:pigeonbr
  • 3
  • 3
9 Comments
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9816637
You could try passing VARIANT_TRUE instead of 1 - that's what I pass when I call SetDifferentFirstPageHeaderFooter().

The other thing is that when I call the function, I've got my page setup from the section, rather than the document - i.e.
   Sections sections(document.GetSections());
   Section section(sections.Item(1));
   PageSetup pageSetup(section.GetPageSetup());
   pageSetup.SetDifferentFirstPageHeaderFooter(VARIANT_TRUE);
However, I'm sure that getting the page setup from the document is still valid.

All the best
Martyn
0
 

Author Comment

by:pigeonbr
ID: 9842916
martyn;

Ok..things are looking up... I need some help here. I've got my footer working. My header is the way I want it for the first page, but it is showing up on all pages. Here is my code:
/*                  //**************************************
                  //Header setup with logo
                  //**************************************
                  HeaderFooter header(headers.Item(1));
                  header.SetLinkToPrevious(FALSE);
                  Range rangeHeader(header.GetRange());

                  InlineShapes shapes(rangeHeader.GetInlineShapes());
                  shapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",&varEmpty,&varEmpty,&varEmpty);
                  rangeHeader.Collapse(&varCollapse);

                  rangeHeader.InsertAfter(strHeaderText1);
                  _Font font(rangeHeader.GetFont());
                  font.SetName("Bookman Old Style Bold");
                  font.SetSize(16.0);


                  rangeHeader.InsertAfter(strHeaderText);
                  font.SetName("Bookman Old Style Bold");
                  font.SetSize(14.0);
                  font.SetUnderline(VARIANT_TRUE);

                  //Insert blank lines to start displaying the table further down so
                  //as to get just the general info on first page.
                  for(lower;lower<26;lower++)
                  {
                        selection.InsertBreak(&varLineBreak);
                        selection.Collapse(&varCollapse);
                  }
                  lower=1;

so, from the code you wrote above, I see how you setup first page from the section. I still don't understand though...how do I apply the line
pageSetup.SetDifferentFirstPageHeaderFooter(VARIANT_TRUE);
to the appropriate header code ?? My guess is to set up two headers, say header1 and header2, with the appropriate code like my sample above, but this code is using the Range object, and you code uses Sections and Section object...I'm lost here. Can you explain the theory behind using two different and using one for the first page only, and please give some sample code. Thanks.
0
 
LVL 8

Accepted Solution

by:
martynjpearson earned 125 total points
ID: 9848703
It could be that you have to call SetDifferentFirstPageHeaderFooter before you do any work on the headers / footers. Alternatively, you could insert a section break after the first page - you can set the headers differently for different sections. So, after the first page, call

range.InsertBreak(wdSectionBreakNextPage);

Then, you can use the code to get the different headers and footers like this :

Sections sections(document.GetSections());
for (int nSection = 1; nSection < sections.GetCount(); nSection++)
{
   Section section(sections.Item(nSection));
   HeadersFooters headers(section.GetHeaders());
   HeaderFooter header(headers.Item(1));

  // And then you can work on your header!
}

Hope this helps
Martyn
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:pigeonbr
ID: 9851805
Hi Martyn;
Ok...just got your responses to my two questions...lots of info there to sink my teeth into..:) You have answered serveral questions I was having.

One thing I would like made a little clearer is if I'm in the middle of the report, say in the second section, how can I check if I'm "after the first page" to inser tsectionbreak in this particular section since the actual number of pages depends on the unknown amount of data coming from the database CStringArray ?? I can understand the logic being applied to the first page of the whole document in my case because I will allways have the same 24 lines of client info on the first page of the document, then I can put in a section break...but in the other sections of the document, this is not the case..so how do I know when to insert the SectionBreakNextPage ?? Can i use the number of lines  ??  I guess so...but how do I go about determining the number of lines on the page? And the last page of a section will not necessarily e full...can you give me some guidelines here please martyn ?? Thanks !
0
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9866051
It's difficult to tell where page breaks occur as this could vary due to differences in fonts, page setup, etc. Are you not inserting your section breaks based on your data - i.e. <some data> section break < some different data> section break < some more unrelated data> etc?
0
 

Author Comment

by:pigeonbr
ID: 9874914
See my otehr post as to how I set up my code please.:)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mac OS 9 (Classic Environment) vs. MacBook Pro OS 10 8 36
Folder Comparison 12 52
substring method in java 1 79
move a line in eclipse 3 60
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now