A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Landscape format for first Word document not setting properly



 
 
Thread Tools Display Modes
  #1  
Old August 16th, 2008, 12:49 AM posted to microsoft.public.word.newusers
Sri
external usenet poster
 
Posts: 49
Default Landscape format for first Word document not setting properly

Dear All

I am reading a group of text files from IntermediateFolder
and converting to word document and setting

font name as courier new ,font size 8 and orientation as landscape.The first
word document orientation is not landscape and rest of the documents
orientation is landscape.This happens only for first document only.If I
interchange the order of the files again the first word document orientation
is not landscape but the rest of the documents are in landscape.

Below you can find my code.The GetOrientation is the method which is reading
the config file and returning a string

When I debugged the dll it is showing me setting as landscape and it is not
setting it for first word document.

I am using office object library 12.0 and my os is windows xp professional
service pack 2 and word 2007 installed on my machine.I am trying to set the
format as 2000 as word 2007 is not available on production box.

I am trying to open all these documents on word 2000 and first one is not
able to set landscape format and rest

of the documents are able to do this.This application works fine on word
2007.What I mean is it opens all the documents correctly with landsacpe
format.the problem is when opening in word 2000 the first document is not

setting the landscape format correctly.I have used the

object FileFormat = WdSaveFormat.wdFormatDocument;//for saving to word 2000
and finally calling the saveas method.Can anyone Please tell me what is the
problem in my code.urgent help required.




Here is the code(Language c#,os:windows xp professional service pack
2,visual studio 2008 ,dotnetframework 2.0

word object library 12.0,word 2007 on my machine)



public void CreateWordDocument(string aNewDateFilePath,string
IntermediateFolder,string DestinationFolder,string FontName,int
FontSize,string SearchPattern)
{
object aNewPathName = aNewDateFilePath;

Console.WriteLine("opening Exisiting file using WordApp");


//Opening the existing notepad file using wordapp instead of
using the filestream to open the file
aOldDoc = WordApp.Application.Documents.Open(ref
aNewPathName, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref format, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing);
Console.WriteLine("Created a new Word Document");

//Create a new word document so that we can copy everything
from text file opened above to word
aNewdoc = WordApp.Documents.Add(ref missing, ref missing,
ref missing, ref missing);


//Make word invisible and activate the new document
WordApp.Visible = false;
aNewdoc.Activate();

//select the old document
aOldDoc.Select();
//copy all the contents of old document to clipboard
WordApp.Selection.Copy();
//select new document
aNewdoc.Select();
//paste all the content from clipboard to new document
WordApp.Selection.PasteSpecial(ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing);

//close the old document
aOldDoc.Close(ref missing, ref missing, ref missing);

//select the New Document
aNewdoc.Select();

//set the font name and size
WordApp.Selection.Font.Name = FontName;
WordApp.Selection.Font.Size = FontSize;


//set the page orientation
try
{


string aOrientation = GetOrientation();
if (aOrientation == "Landscape")
WordApp.Selection.PageSetup.Orientation =
WdOrientation.wdOrientLandscape;
else
WordApp.Selection.PageSetup.Orientation =
WdOrientation.wdOrientPortrait;
}
catch (Exception exx)
{
Console.WriteLine("source is : " + exx.Source);
Console.WriteLine("Error in orientation is : " +
exx.Message);
}


//set the left,right,top and bottom margins
WordApp.Selection.PageSetup.LeftMargin =
WordApp.CentimetersToPoints(1.00F);
WordApp.Selection.PageSetup.RightMargin =
WordApp.CentimetersToPoints(1.00F);
WordApp.Selection.PageSetup.TopMargin =
WordApp.CentimetersToPoints(0.18F);
WordApp.Selection.PageSetup.BottomMargin =
WordApp.CentimetersToPoints(1.00F);

//change the extension to .doc
string aNewpath = Path.ChangeExtension(aNewDateFilePath,
".doc");
aNewIntermediateFolder =
IntermediateFolder.Substring(IntermediateFolder.La stIndexOf("\\",
IntermediateFolder.Length));
Console.WriteLine("aIntermediateFolder in word:" +
aIntermediateFolder);

aNewIntermediateFolder = aNewIntermediateFolder.Substring(1);
Console.WriteLine("aNewIntermediateFolder in substring: " +
aNewIntermediateFolder);
string aDestinationFolder =
DestinationFolder.Substring(DestinationFolder.Last IndexOf("\\",
DestinationFolder.Length));
Console.WriteLine("aDestinationFolder in word:" +
aDestinationFolder);
string aNewDestinationFolder =
aDestinationFolder.Substring(1);
Console.WriteLine("aNewDestinationFolder in substring: " +
aNewDestinationFolder);

//string aDestinationPathName =
aNewpath.Replace(aNewIntermediateFolder, aNewDestinationFolder);

//Replace intermediatefolder with destinationfolderpath
string aDestinationPathName =
aNewpath.Replace(IntermediateFolder, DestinationFolder);
Console.WriteLine("Changing path of Intermediate folder to
Destination folder in word:" + aDestinationPathName);
aDestPathName = aDestinationPathName;


//saving in word 2000 format
object FileFormat = WdSaveFormat.wdFormatDocument;
aNewdoc.SaveAs(ref aDestPathName, ref FileFormat, ref
missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing);


}
aNewdoc.Close(ref missing, ref missing, ref missing);

Console.WriteLine("------------------------------------------------------------------------");
File.Delete(aFileName);
Console.WriteLine("Deleted the" + " " + aFileName + " "
+"file from source folder...");

Console.WriteLine("------------------------------------------------------------------------");
}
Console.WriteLine("Finally Quitting and Releasing the word
document references");
WordApp.Quit(ref missing, ref missing, ref missing);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(WordApp);
}



Thanks

sri

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:46 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.