Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here's the code I am using:

C#
double year = DateTime.Now.Year;
            double month = DateTime.Now.Month;
            double day = DateTime.Now.Day;
            string a = "Report date: " + month.ToString() + "/" + day.ToString() + "/" + year.ToString();
            //INSERTING TAB CHARACTERS
            oWord.ActiveWindow.Selection.TypeText("\t");
            //DATE:
            oWord.ActiveWindow.Selection.TypeText(a);
            oWord.ActiveWindow.Selection.Fields.Add(oWord.Selection.Range, ref CurrentPage, ref oMissing, ref oMissing);



Here is the output:



Page 1 Report date: 4/2/20121

I really have no idea why this is happening.
Posted
Comments
ZurdoDev 2-Apr-12 16:09pm    
You should be able to step through the code and see what happens.
Herman<T>.Instance 2-Apr-12 16:11pm    
is it ref CurrentPage that is shown again?

1 solution

C#
double year = DateTime.Now.Year;
string a = year.ToString();


Will return 2012, so that trailing '1' is coming from somewhere else. I think digi is on to something, can you see if it happens on another page?
 
Share this answer
 
Comments
vlad781 2-Apr-12 16:43pm    
Ok, well, on the next page, the 1 becomes a 2 (20122), page three turns to 3, 20123. So I assume that it is showing the pagenumber as well as the date.

I assumed correctly. In this section of my code, I was placing a page number in the footer and aligning it left. Then it was supposed to indent and create the date. here is my mistake: oWord.ActiveWindow.Selection.Fields.Add(oWord.Selection.Range, ref CurrentPage, ref oMissing, ref oMissing); it adds a number value that is indicated in another part of my code.
The fix: commenting it out/ deleting that line.
My copy+paste problem.

Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900