Solved

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

Posted on 2003-11-24
9
346 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
windows 10 how make picture as desktop background 2 63
sumDigits challenge 9 150
Use of condition with 'serial' in ansible 2 62
how to split multiple lines delimiter : 8 99
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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