pigeonbr
asked on
For martynjpearson:Getting a CString into a COleVariant
Hi again;
I've been working hard on my problems...if I do this to get both date and text and page number one beside the other in the footer:
Sections sections(oDocument.GetSect ions()); // document is your instance of _Document
Section section1(sections.Item(1)) ;
HeadersFooters footers(section1.GetFooter s());
HeaderFooter footer1(footers.Item(1));
footer1.SetLinkToPrevious( FALSE);
Range range(footer1.GetRange());
Fields fields(range.GetFields());
COleVariant varType((long)wdFieldDate) ;//puts date at left of footer
COleVariant varType1((long)wdFieldPage );//puts page number at left of footer
COleVariant varEmpty(DISP_E_PARAMNOTFO UND, VT_ERROR);
COleVariant varCollapseEnd((long)wdCol lapseEnd);
CString strPage(" Page ");
COleVariant varText;
varText=COleVariant(strPag e);
CString strInspecTitle(" INSPEC-Inspections de bâtiment ");
COleVariant varTextInspec;
varTextInspec=COleVariant( strInspecT itle);
fields.Add(range, &varType, &varEmpty, &varEmpty);
range.Collapse(varCollapse End);
fields.Add(range,&varText, &varEmpty, &varEmpty);
range.Collapse(varCollapse End);
fields.Add(range, &varType1, &varEmpty, &varEmpty);
range.Collapse(varCollapse End);
fields.Add(range, &varTextInspec, &varEmpty, &varEmpty);
....I get a run error in the line :
fields.Add(range,&varText, &varEmpty, &varEmpty);
...where I'm taking a CString putting it into a COleVariant, and then adding it to the display, but it crashes here...seems to have no problems doing the conversion, but gives me a "Failed" at run time when it gets to this line. Any ideas ? Am I not converting my text to display properly ? Thanks!
I've been working hard on my problems...if I do this to get both date and text and page number one beside the other in the footer:
Sections sections(oDocument.GetSect
Section section1(sections.Item(1))
HeadersFooters footers(section1.GetFooter
HeaderFooter footer1(footers.Item(1));
footer1.SetLinkToPrevious(
Range range(footer1.GetRange());
Fields fields(range.GetFields());
COleVariant varType((long)wdFieldDate)
COleVariant varType1((long)wdFieldPage
COleVariant varEmpty(DISP_E_PARAMNOTFO
COleVariant varCollapseEnd((long)wdCol
CString strPage(" Page ");
COleVariant varText;
varText=COleVariant(strPag
CString strInspecTitle(" INSPEC-Inspections de bâtiment ");
COleVariant varTextInspec;
varTextInspec=COleVariant(
fields.Add(range, &varType, &varEmpty, &varEmpty);
range.Collapse(varCollapse
fields.Add(range,&varText,
range.Collapse(varCollapse
fields.Add(range, &varType1, &varEmpty, &varEmpty);
range.Collapse(varCollapse
fields.Add(range, &varTextInspec, &varEmpty, &varEmpty);
....I get a run error in the line :
fields.Add(range,&varText,
...where I'm taking a CString putting it into a COleVariant, and then adding it to the display, but it crashes here...seems to have no problems doing the conversion, but gives me a "Failed" at run time when it gets to this line. Any ideas ? Am I not converting my text to display properly ? Thanks!
ASKER
martyn,
An actual code sample would really be nice here:) since I'm a beginner in automation. I've been racking my brains on this one for 2 weeks every evening...getting closer, but I need this ready for monday...thanks:)
An actual code sample would really be nice here:) since I'm a beginner in automation. I've been racking my brains on this one for 2 weeks every evening...getting closer, but I need this ready for monday...thanks:)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
martyn;
Thanks for the code sample...I really appreciate it. from this I gather I can use the same setup for a header. The only thing still illuding me is the setup for getting different headers for different parts of a documnet... we are working that subject together on another question...I will do some more work and get back to you in my other question...thanks very very much...I am getting to understand what is going on. It's not obvious when you've never done it, even from reading etc....thanks again martyn,..really appreciate it.
Thanks for the code sample...I really appreciate it. from this I gather I can use the same setup for a header. The only thing still illuding me is the setup for getting different headers for different parts of a documnet... we are working that subject together on another question...I will do some more work and get back to you in my other question...thanks very very much...I am getting to understand what is going on. It's not obvious when you've never done it, even from reading etc....thanks again martyn,..really appreciate it.
If you want to have a field, then some text, and then some more fields, I believe you'll have to get the start range, get the fields collection, add your field(s), collapse the range, add some text, collapse the range, get the fields collection, add your field(s)... etc.
Hope this helps
Martyn