Menu

 

Saturday, August 7, 2010

Refernce Collection (Z) :- Zoom Collection

VBA Code :-

ActiveDocument.ActiveWindow.ActivePane _
.Zooms(wdNormalView).Percentage = 100
*
ActiveDocument.ActiveWindow.ActivePane _
.Zooms(wdPrintView).PageFit = wdPageFitFullPage

C# Code :-

public void ZoomCollection()
{
ThisApplication.ActiveDocument.ActiveWindow.ActivePane.Zooms.Item(Microsoft.Office.Interop.Word.WdViewType.wdNormalView).Percentage = 100;

ThisApplication.ActiveDocument.ActiveWindow.ActivePane.Zooms.Item(Microsoft.Office.Interop.Word.WdViewType.wdPrintPreview).PageFit = Microsoft.Office.Interop.Word.WdPageFit.wdPageFitFullPage;


}

Refernce Collection (X) :- XmlChildNode Suggestion,XMlNameSpace,XMlNodes,XMLSchema,XSL Transform

VBA Code :-

Dim objSuggestion As XMLChildNodeSuggestion
Dim objNode As XMLNode

Set objNode = Selection.XMLNodes.Item(1)

For Each objSuggestion In objNode.ChildNodeSuggestions
objSuggestion.Insert
Selection.MoveRight
Next

C# Code :-

public void XmlChildCollection()
{
Word.XMLChildNodeSuggestion wordXmlChildNodeCollection = null;
Word.XMLNodes objNode = null;
int i =1;
objNode = ThisApplication.Selection.XMLNodes ;
foreach (Word.XMLChildNodeSuggestions wordXmlChild in objNode)
{

object objitem = i;
Word.Range wordrange = ThisApplication.Selection.Range;
object obj = wordrange;
wordXmlChild.get_Item(ref objitem).Insert(ref obj);
i++;
}

}

VBA Code :-

Sub ApplySampleSchema()
Dim objSchema As XMLNamespace

For Each objSchema In Application.XMLNamespaces
If objSchema.URI = "SimpleSample" Then
objSchema.AttachToDocument ActiveDocument
Exit For
End If
Next
End Sub

C# Code :-

public void ApplySampleSchema()
{
Word.XMLNamespaces objschema = ThisApplication.XMLNamespaces;

foreach (Word.XMLNamespace objSchema in objschema)
{
if (objSchema.URI == "SimpleSample")
{
object activeDocument = ThisApplication.ActiveDocument;
objSchema.AttachToDocument(ref activeDocument);
}

}
}

VBA Code :-


Dim objNode As XMLNode

For Each objNode In ActiveDocument.XMLNodes
objNode.Validate
If objNode.ValidationStatus <> wdXMLValidationStatusOK Then
MsgBox objNode.ValidationErrorText(True)
End If
Next

C# Code :-

public void XmlNodes()
{
Word.XMLNode objNode = null;

foreach (Word.XMLNode xmlnode in ThisApplication.ActiveDocument.XMLNodes)
{
if (xmlnode.ValidationStatus != Microsoft.Office.Interop.Word.WdXMLValidationStatus.wdXMLValidationStatusOK)
{
object objTrue = true;
xmlnode.SetValidationError(Microsoft.Office.Interop.Word.WdXMLValidationStatus.wdXMLValidationStatusOK, ref objTrue, true);
}
}
}

VBA Code :-

Dim objNode As XMLNode
Dim intResponse As Integer

Set objNode = Selection.XMLNodes.Add("example", "SimpleSample")

objNode.Validate

If objNode.ValidationStatus < 0 Then
intResponse = MsgBox("This element is invalid. " & _
"Are you sure you want to add it?", vbYesNo)
If intResponse = vbNo Then objNode.Delete
End If

C# Code :-

public void XmlNodes()
{
Word.XMLNodes xmlNodes = ThisApplication.ActiveDocument.XMLNodes;
Word.XMLNode xmlNode = ThisApplication.ActiveDocument.XMLNodes[1];

string stgrName = "example";
string strnamespace = "SimpleSample";
xmlNode = ThisApplication.Selection.XMLNodes.Add(stgrName, strnamespace, ref missing);
xmlNode.Validate();

if (xmlNode.ValidationStatus < 0)
{
}


}

VBA Code :-

Sub VerifySampleSchema()
Dim objNS As XMLNamespace
Dim objSchema As XMLSchemaReference
Dim blnSchemaAttached As Boolean

For Each objSchema In ActiveDocument.XMLSchemaReferences
If objSchema.NamespaceURI <> "SimpleSample" Then
blnSchemaAttached = False
Else
objSchema.Reload
blnSchemaAttached = True
Exit For
End If
Next

If blnSchemaAttached = False Then
Set objNS = Application.XMLNamespaces.Item("SimpleSample")
objNS.AttachToDocument (ActiveDocument)
End If
End Sub

C# Code :-

public void BerifySampleSchema()
{
bool myvalue = false;

foreach (Word.XMLSchemaReference xmlRef in ThisApplication.ActiveDocument.XMLSchemaReferences)
{
if (xmlRef.NamespaceURI != "SimpleSample")
{
myvalue = true;
}
else
{
myvalue = false;
}
}

}

Refernce Collection (W) :- Windows , Words

VBA Code :-

Windows.Arrange ArrangeStyle:=wdTiled
*
ActiveDocument.ActiveWindow.NewWindow
NewWindow
Windows.Add
*
MsgBox Windows(1).Caption

C# Code :-

public void WindowCollection()
{
object objwdTitled = Word.WdArrangeStyle.wdTiled;

ThisApplication.Windows.Arrange(ref objwdTitled);

ThisApplication.ActiveDocument.ActiveWindow.NewWindow();

object objActiveWindo = 1;
string strCaption = "";
strCaption = ThisApplication.Windows.get_Item(ref objActiveWindo).Caption;
}

VBA Code :-

MsgBox Selection.Words.Count & " words are selected"

With Selection.Words(1)
.Italic = True
.Font.Size = 24
End With

C# Code :-

public void SelectionWord()
{
int wordCount = ThisApplication.Selection.Words.Count;

ThisApplication.Selection.Words[1].Italic = 1;
ThisApplication.Selection.Words[1].Font.Size = 24;

}

Refernce Collection (V) :- Variables , Version

VBA Code :-

For Each aVar In ActiveDocument.Variables
If aVar.Name = "Blue" Then num = aVar.Index
Next aVar
If num = 0 Then
ActiveDocument.Variables.Add Name:="Blue", Value:=6
Else
ActiveDocument.Variables(num).Value = 6
End If

C# Code :-

public void Variables()
{
Word.Variables wordvariables = ThisApplication.ActiveDocument.Variables;
int num = 0;
foreach (Word.Variable wordvar in wordvariables)
{
if (wordvar.Name == "Blue")
{
num = wordvar.Index;
}
string strName = "";
object obj = null;
if (num == 0)
{
strName = "Blue";
obj = 6;
ThisApplication.ActiveDocument.Variables.Add(strName, ref obj);
}
else
{
obj = num;
ThisApplication.ActiveDocument.Variables.get_Item(ref obj).Value = strName;
}

}
}

VBA Code :-

ScreenUpdating = False
With ActiveDocument.AttachedTemplate.OpenAsDocument
.Variables.Add Name:="UserName", Value:= Application.UserName
.Close SaveChanges:=wdSaveChanges
End With

C# Code :-

public void AttachedTemplateOpenAsDocument()
{
ThisApplication.ScreenUpdating = false;

string UserName = "Avinash";
object obj = this.Application.UserName;

Word.Template wordTemp = (Word.Template)ThisApplication.ActiveDocument.get_AttachedTemplate();
wordTemp.OpenAsDocument().Variables.Add(UserName, ref obj);

object objsavechanges = Word.WdSaveOptions.wdSaveChanges;
wordTemp.OpenAsDocument().Close(ref objsavechanges, ref missing, ref missing);
}

VBA Code :-

ActiveDocument.Versions.AutoVersion = wdAutoVersionOff
*
ActiveDocument.Versions.Save _
Comment:="incorporated Judy's revisions"

*
If ActiveDocument.Versions.Count >= 1 Then
With ActiveDocument.Versions(1)
MsgBox "Comment = " & .Comment & vbCr & "Author = " & _
.SavedBy & vbCr & "Date = " & .Date
End With
End If

C# Code :-

public void versioningSamples()
{
ThisApplication.ActiveDocument.Versions.AutoVersion = Microsoft.Office.Interop.Word.WdAutoVersions.wdAutoVersionOff;

object commenst = "Avinash revsion";
ThisApplication.ActiveDocument.Versions.Save(ref commenst);

if (ThisApplication.ActiveDocument.Versions.Count >= 1)
{
String comments = ThisApplication.ActiveDocument.Versions[1].Comment;
String SavedBy = ThisApplication.ActiveDocument.Versions[1].SavedBy;

}

}

Refence Collection :- (T) TAbleOFAuthorties , TableOfContent,TableOfFiq,Tables,TablesOfAuthorites,TableOFAutoCat,TableOfContents,TableOfFiq,TableStops

VBA Code :-

With ActiveDocument.TablesOfAuthorities(1)
.IncludeCategoryHeader = True
.Update
End With

C# Code :-

public void TOA()
{
ThisApplication.ActiveDocument.TablesOfAuthorities[1].IncludeCategoryHeader = true;
ThisApplication.ActiveDocument.TablesOfAuthorities[1].Update();
}

VBA Code :-

Set myRange = ActiveDocument.Range(Start:=0, End:=0)
ActiveDocument.TablesOfAuthorities.Add Range:=myRange, _
Passim:=True, Category:=0, EntrySeparator:=", "

C# Code :-

public void TOARange()
{

object start = 0;
object End = 0;
object Category = 0;
object Passim = true;
object EntrySeparator = ", ";

Word.Range myRange = ThisApplication.ActiveDocument.Range(ref start, ref End);
ThisApplication.ActiveDocument.TablesOfAuthorities.Add(myRange, ref Category, ref missing, ref Passim, ref missing, ref missing, ref missing, ref EntrySeparator, ref missing, ref missing, ref missing);

}

VBA Code :-

ActiveDocument.TablesOfContents(1).UpdatePageNumbers
*

Set myRange = ActiveDocument.Range(Start:=0, End:=0)
ActiveDocument.TablesOfContents.Add Range:=myRange, _
UseFields:=False, UseHeadingStyles:=True, _
LowerHeadingLevel:=3, _
UpperHeadingLevel:=1

C# Code :-

public void TOAObject()
{
ThisApplication.ActiveDocument.TablesOfContents[1].UpdatePageNumbers();
object start = 0;
object End = 0;
object Category = 0;
object Passim = true;
object EntrySeparator = ", ";

Word.Range myRange = ThisApplication.ActiveDocument.Range(ref start, ref End);
ThisApplication.ActiveDocument.TablesOfAuthorities.Add(myRange, ref Category, ref missing, ref Passim, ref missing, ref missing, ref missing, ref EntrySeparator, ref missing, ref missing, ref missing);

}

VBA Code :-

ActiveDocument.TablesOfFigures(1).UpdatePageNumbers


*
ActiveDocument.TablesOfFigures.Add Range:=Selection.Range, _
IncludeLabel:=True, IncludePageNumbers:=True

C# Code :-

public void TableFig()
{
ThisApplication.ActiveDocument.TablesOfFigures[1].UpdatePageNumbers();

object start = 0;
object End = 0;
object Include = true;
object IncludePagenumbers = true;

Word.Range myRange = ThisApplication.ActiveDocument.Range(ref start, ref End);
ThisApplication.ActiveDocument.TablesOfFigures.Add(myRange, ref missing, ref Include, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref IncludePagenumbers, ref missing, ref missing, ref missing);

}

VBA Code :-

For Each aTable In ActiveDocument.Tables
aTable.Borders.OutsideLineStyle = wdLineStyleSingle
aTable.Borders.OutsideLineWidth = wdLineWidth025pt
aTable.Borders.InsideLineStyle = wdLineStyleNone
Next aTable

C# Code :-

public void TablewdLineStyle()
{
Word.Tables wordTables = ThisApplication.ActiveDocument.Tables;

foreach (Word.Table wordTable in wordTables)
{
wordTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
wordTable.Borders.OutsideLineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt;
wordTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
}


}

VBA Code :-

For Each aTable In ActiveDocument.Tables
aTable.Borders.OutsideLineStyle = wdLineStyleSingle
aTable.Borders.OutsideLineWidth = wdLineWidth025pt
aTable.Borders.InsideLineStyle = wdLineStyleNone
Next aTable
*

Set myRange = ActiveDocument.Range(Start:=0, End:=0)
ActiveDocument.Tables.Add Range:=myRange, NumRows:=3, NumColumns:=4
*

ActiveDocument.Tables(1).ConvertToText Separator:=wdSeparateByTabs

C# Code :-

public void TablewdLineStyle()
{
Word.Tables wordTables = ThisApplication.ActiveDocument.Tables;

foreach (Word.Table wordTable in wordTables)
{
wordTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
wordTable.Borders.OutsideLineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt;
wordTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
}

object start = 0;
object End = 0;

Word.Range wordRange = ThisApplication.ActiveDocument.Range(ref start, ref End);
ThisApplication.ActiveDocument.Tables.Add(wordRange, 3, 4, ref missing, ref missing);

object sep = Word.WdSeparatorType.wdSeparatorColon;

ThisApplication.ActiveDocument.Tables[1].ConvertToText(ref sep, ref missing);


}

VBA Code :-

ActiveDocument.TablesOfAuthorities.Format = wdTOAClassic
*
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
ActiveDocument.TablesOfAuthorities.Add Range:=myRange, _
Passim:=True, Category:=0, EntrySeparator:= ", "
*

With ActiveDocument.TablesOfAuthorities(1)
.IncludeCategoryHeader = True
.Update
End With

C# Code :-

public void TablesOfAuth()
{
ThisApplication.ActiveDocument.TablesOfAuthorities.Format = Microsoft.Office.Interop.Word.WdToaFormat.wdTOADistinctive;


object start = 0;
object End = 0;

Word.Range wordRange = ThisApplication.ActiveDocument.Range(ref start, ref End);

object passim = true;
object Category = 0;
object EntrySep = ", ";
ThisApplication.ActiveDocument.TablesOfAuthorities.Add(wordRange, ref Category, ref missing, ref passim, ref missing, ref EntrySep, ref missing, ref missing, ref missing, ref missing, ref missing);

ThisApplication.ActiveDocument.TablesOfAuthorities[1].IncludeCategoryHeader = true;
ThisApplication.ActiveDocument.TablesOfAuthorities[1].Update();

}

VBA Code :-

ActiveDocument.TablesOfContents.MarkEntry Range:=Selection.Range, _
Level:=2, Entry:="Introduction"
*


Set myRange = ActiveDocument.Range(Start:=0, End:=0)
ActiveDocument.TablesOfContents.Add Range:=myRange, _
UseFields:=False, UseHeadingStyles:=True, _
LowerHeadingLevel:=3, _
UpperHeadingLevel:=1

C# Code :-

public void MarkEntry()
{
Word.Range wordRange = ThisApplication.Selection.Range;
object Entery = "Introduction";
object Level = 2;
ThisApplication.ActiveDocument.TablesOfContents.MarkEntry(wordRange, ref Entery, ref missing, ref missing, ref Level);


object UserFiled = false;
object UseHeadingStyles = true;
object LowerHeadingLevel = 3;

object UpperHeadingLevel = 1;

ThisApplication.ActiveDocument.TablesOfContents.Add(wordRange, ref UseHeadingStyles, ref UpperHeadingLevel, ref LowerHeadingLevel, ref UserFiled, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);


}

Friday, August 6, 2010

Refernce Collection :- (S) Sections , Sentences , ShapesNodes , Shapes , SmartTagActions, SmartTagRecongnizers , SmartTag, Smart tags , SpellingSugges

VBA Code :-

With ActiveDocument.Sections.Last.Range
.Collapse Direction:=wdCollapseEnd
.InsertAfter "end of document"
End With

C# Code :-

public void SectionswdCollaseEnd()
{
object Directions = Word.WdCollapseDirection.wdCollapseEnd;
string strtext = "End of Document";

ThisApplication.ActiveDocument.Sections.Last.Range.Collapse(ref Directions);
ThisApplication.ActiveDocument.Sections.Last.Range.InsertAfter(strtext);

}

VBA Code :-

Set myRange = ActiveDocument.Range(Start:=0, End:=0)
ActiveDocument.Sections.Add Range:=myRange
myRange.InsertParagraphAfter

C# Code :-

public void insertPara()
{
object start = 0;
object end = 0;
Word.Range myRange = ThisApplication.ActiveDocument.Range(ref start, ref end);
object objrange = myRange;

ThisApplication.ActiveDocument.Sections.Add(ref objrange, ref missing);
myRange.InsertParagraph();
}

VBA Code :-

MsgBox ActiveDocument.Sections.Count & " sections"
Selection.Paragraphs(1).Range.InsertBreak _
Type:=wdSectionBreakContinuous
MsgBox ActiveDocument.Sections.Count & " sections"

C# Code :-

public void wdsectionBreakContinous()
{
int secCount = ThisApplication.ActiveDocument.Sections.Count;
string strCount = System.Convert.ToString(secCount);
MessageBox.Show(strCount);

Word.WdBreakType wordBreak = Microsoft.Office.Interop.Word.WdBreakType.wdSectionBreakContinuous;
object objwordBreak = wordBreak;
ThisApplication.Selection.Paragraphs[1].Range.InsertBreak(ref objwordBreak);
}

VBA Code :-

With ActiveDocument.Sections(1).PageSetup
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
End With

C# Code :-

public void ActiveDocumentSection()
{
ThisApplication.ActiveDocument.Sections[1].PageSetup.LeftMargin = ThisApplication.InchesToPoints(0.5f);
ThisApplication.ActiveDocument.Sections[1].PageSetup.LeftMargin = ThisApplication.InchesToPoints(0.5f);

}

VBA Code :-

MsgBox Selection.Sentences.Count & " sentences are selected"

*
With ActiveDocument.Sentences(1)
.Bold = True
.Font.Size = 24
End With

C# Code :-


public void SentenceCount()
{
int SentenceCount = ThisApplication.Selection.Sentences.Count;
string strSentCount = System.Convert.ToString(SentenceCount);
MessageBox.Show(strSentCount);

ThisApplication.ActiveDocument.Sentences[1].Bold = 1;
ThisApplication.ActiveDocument.Sentences[1].Font.Size = 24.0f;
}

VBA Code :-

ActiveDocument.Shapes(3).Nodes.Delete 4
*
With ActiveDocument.Shapes(3).Nodes
.Insert 4, msoSegmentCurve, msoEditingSmooth, 210, 100
End With

*
With ActiveDocument.Shapes(3)
If .Nodes(1).EditingType = msoEditingCorner Then
.Nodes.SetEditingType 1, msoEditingSmooth
End If
End With

C# Code :-

public void ShapesNodecollections()
{
object objgetItem= 3;
ThisApplication.ActiveDocument.Shapes.get_Item(ref objgetItem).Delete();

ThisApplication.ActiveDocument.Shapes.get_Item(ref objgetItem).Nodes.Insert(4, Microsoft.Office.Core.MsoSegmentType.msoSegmentCurve, Microsoft.Office.Core.MsoEditingType.msoEditingSmooth, 210f, 100f, 0f, 0f, 0f, 0f);

if (ThisApplication.ActiveDocument.Shapes.get_Item(ref objgetItem).Nodes.get_Item(ref objgetItem).EditingType == Microsoft.Office.Core.MsoEditingType.msoEditingCorner)
{
ThisApplication.ActiveDocument.Shapes.get_Item(ref objgetItem).Nodes.SetEditingType(1, Microsoft.Office.Core.MsoEditingType.msoEditingSmooth);
}

}

VBA Code :-

ActiveDocument.Shapes.SelectAll

*
ActiveDocument.Shapes.AddShape msoShapeRectangle, 50, 50, 100, 200

*

ActiveDocument.Shapes(1).Flip msoFlipHorizontal

C# Code :-

public void ShapesCollection()
{
object objId = 1;

ThisApplication.ActiveDocument.Shapes.SelectAll();

ThisApplication.ActiveDocument.Shapes.AddShape(1, 50f, 50f, 100f, 100f, ref missing);

ThisApplication.ActiveDocument.Shapes.get_Item(ref objId).Flip(Microsoft.Office.Core.MsoFlipCmd.msoFlipHorizontal);
}

VBA Code :-

Sub GetSmartTagsByType()
Dim objSmartTag As SmartTag
Dim objSmartTags As SmartTags
Dim strSmartTagName As String

strSmartTagName = "urn:schemas-microsoft-com" & _
":office:smarttags#address"

Set objSmartTags = ActiveDocument.SmartTags _
.SmartTagsByType(strSmartTagName)

For Each objSmartTag In objSmartTags
objSmartTag.SmartTagActions.ReloadActions
Next
End Sub

C# Code :-

public void GetSmartTagsType()
{
Word.SmartTags objSmartTags = null;
string strSmartTagName = "";

strSmartTagName = "urn:schemas-microsoft-com :office:smarttags#address";

objSmartTags = ThisApplication.ActiveDocument.SmartTags.SmartTagsByType(strSmartTagName);

foreach (Word.SmartTag objSmartTag in objSmartTags)
{
objSmartTag.SmartTagActions.ReloadActions();
}

}

VBA Code :-

Sub CheckforSmartTagRecognizers()

' Handle run-time error if no smart tag recognizers exist.
On Error Goto No_SmartTag_Recognizers_In_List

' Notify the user of the first smart tag recognizer item.
MsgBox "The first smart tag recognizer is: " & _
Application.SmartTagRecognizers.Item(1)
Exit Sub

No_SmartTag_Recognizers_In_List:
MsgBox "No smart tag recognizers exist in list."

End Sub

C# Code :-

public void CheckforSmartTagRecognizers()
{
object objItem =1;
string strCaptionName = "";
strCaptionName = ThisApplication.SmartTagRecognizers.get_Item(ref objItem).Caption;
}

VBA Code :-

Sub NewSmartTagProp()
ActiveDocument.SmartTags(1).Properties _
.Add Name:="President", Value:=True
End Sub

C# Code :-

public void NewSmartTagProp()
{
object objGetItem =1;
string strName ="Avinash";
string strValue = "Tiwari";
ThisApplication.ActiveDocument.SmartTags.get_Item(ref objGetItem).Properties.Add(strName, strValue);
}

VBA Code :-

For Each wd In ActiveDocument.Words
Set sugg = wd.GetSpellingSuggestions
If sugg.Count <> 0 Then
For Each ss In sugg
MsgBox ss.Name
Next ss
End If
Next wd

C# Code :-

public void SpellingSuggestion()
{
Word.SpellingSuggestions sugg = null;


foreach (Word.Application wd in ThisApplication.ActiveDocument.Words)
{
Word.Range wordRange = wd.Selection.Words[1];
string strValue = wordRange.Text ;
sugg = wd.GetSpellingSuggestions(strValue, 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);

foreach(Word.SpellingSuggestion ss in sugg)
{
if(sugg.Count != 0)
{
string strName = ss.Name;
}
}

}

}

VBA Code :-

For Each sty In ActiveDocument.Styles
If sty.BuiltIn = False Then sty.Delete
Next sty

C# Code :-

public void ActiveDocumetStyles()
{
Word.Style wordStyle = null;
int i = 0;
foreach (Word.Styles wordstyle in ThisApplication.ActiveDocument.Styles)
{
object obji = i;
if (wordstyle.get_Item(ref obji ).BuiltIn == false)
{
wordstyle.get_Item(ref obji).Delete();
}
}
}

VBA Code :-

Set myStyle = ActiveDocument.Styles.Add(Name:="Introduction", _
Type:=wdStyleTypeCharacter)
With myStyle.Font
.Bold = True
.Italic = True
.Name = "Arial"
.Size = 12
End With
Selection.Range.Style = "Introduction"

C# Code :-

public void CreateWordStyle()
{
string Name = "Introduction";
object objStyle = Word.WdStyleType.wdStyleTypeCharacter;

Word.Style wordStyle = ThisApplication.ActiveDocument.Styles.Add(Name, ref objStyle);
wordStyle.Font.Bold = 1;
wordStyle.Font.Italic = 1;
wordStyle.Font.Name = "Arial";
wordStyle.Font.Size = 12;
object Introduction = "Introduction";
ThisApplication.Selection.Range.set_Style(ref Introduction);
}

VBA Code :-

Sub AddCSS()
With ActiveDocument.StyleSheets
.Add FileName:="Web.css", Title:="Web Styles"
.Add FileName:="New.css", Linktype:=wdStyleSheetLinkTypeImported, _
Title:="New Styles"
.Add FileName:="Defs.css", Title:="Definitions", _
Precedence:=wdStyleSheetPrecedenceHighest
End With
End Sub

C# Code :-

public void AddCSS()
{
string strName = "Web.css";
string strTitle = "Web Styles";
ThisApplication.ActiveDocument.StyleSheets.Add(strName, Microsoft.Office.Interop.Word.WdStyleSheetLinkType.wdStyleSheetLinkTypeImported, strTitle, Microsoft.Office.Interop.Word.WdStyleSheetPrecedence.wdStyleSheetPrecedenceHigher);


}

Refernce Collection :- (R) Readability Statics, RecentFiles,Rectangle,Reviews,Revisons,Rows

VBA Code :-

For each rs in Selection.Range.ReadabilityStatistics
Msgbox rs.Name & " - " & rs.Value
Next rs

Set myRange = ActiveDocument.Content
wordval = myRange.ReadabilityStatistics(1).Value
Msgbox wordval

C# Code :-

public void ReadabilityStatics()
{
Word.ReadabilityStatistics wordReadStatics = ThisApplication.Selection.Range.ReadabilityStatistics;

foreach (Word.ReadabilityStatistic wordRead in wordReadStatics)
{
string strName = "";
strName = wordRead.Name;
float strValue ;
strValue = wordRead.Value;

}

VBA Code :-

RecentFiles.Maximum = 5
*
If ActiveDocument.Saved = True Then
RecentFiles.Add Document:=ActiveDocument.FullName, _
ReadOnly:=True
End If

*
If RecentFiles.Count >= 1 Then RecentFiles(1).Open

C# Code :-

public void RecentFiles()
{
ThisApplication.RecentFiles.Maximum = 5;

if (ThisApplication.ActiveDocument.Saved == true)
{
object document = ThisApplication.ActiveDocument.FullName;
object ReadOnly = true;
ThisApplication.RecentFiles.Add(ref document, ref ReadOnly);
}

if (ThisApplication.RecentFiles.Count >= 1)
{
ThisApplication.RecentFiles[1].Open();
}
}

VBA Code :-

Dim objRectangles As Rectangles

Set objRectangles = ActiveDocument.ActiveWindow _
.Panes(1).Pages(1).Rectangles

C# Code :-

public void Rectanges()
{
Word.Rectangles wordRect = ThisApplication.ActiveDocument.ActiveWindow.Panes[1].Pages[1].Rectangles;
}

VBA Code :-

Sub HideAuthorRevisions(blnRev As Boolean)
ActiveWindow.View.Reviewers(Index:=1) _
.Visible = False
End Sub

C# Code :-

public void hideAutorRevesion()
{
object objectvalue = 1;

ThisApplication.ActiveWindow.View.Reviewers.get_Item(ref objectvalue).Visible = false;
}

VBA Code :-

MsgBox ActiveDocument.Revisions.Count
*
For Each myRev In Selection.Range.Revisions
myRev.Accept
Next myRev
*
Set myRange = Selection.Paragraphs(1).Range
myRange.Revisions.AcceptAll
*
ActiveDocument.TrackRevisions = True
Selection.InsertBefore "The "
*
MsgBox ActiveDocument.Sections(1).Range.Revisions(1).Author

C# Code

public void Revisions()
{
int revCount = ThisApplication.ActiveDocument.Revisions.Count;

Word.Revisions wordRevesions = ThisApplication.Selection.Range.Revisions;

foreach (Word.Revision wordRev in wordRevesions)
{
wordRev.Accept();
}

Word.Range wordRange = ThisApplication.Selection.Paragraphs[1].Range;
wordRange.Revisions.AcceptAll();

ThisApplication.ActiveDocument.TrackRevisions = true;
string strInsertBefore = "The ";
ThisApplication.Selection.InsertBefore(strInsertBefore);

string strAutName = "";
strAutName = ThisApplication.ActiveDocument.Sections[1].Range.Revisions[1].Author;


}

VBA Code :-

ActiveDocument.Tables(1).Rows.Alignment = wdAlignRowCenter
*
If Selection.Information(wdWithInTable) = True Then
Selection.Rows.Add BeforeRow:=Selection.Rows(1)
End If

C# Code :-
public void RowAligment()
{
ThisApplication.ActiveDocument.Tables[1].Rows.Alignment = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowCenter;
bool isTable =(bool)ThisApplication.Selection.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdWithInTable);
if (isTable)
{
object before = 1;
ThisApplication.Selection.Rows.Add(ref before);

}
}

Refernce Collection :- (P) PageNumber , Page Collection , Panes Collection , ParaGraph Collection , ProofReadingErros

VBa Code :-

ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary) _
.PageNumbers.StartingNumber = 3

C# Code :-

public void StartingPageNumber()
{
ThisApplication.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.StartingNumber = 3;
}

VBA Code :-

With ActiveDocument.Sections(1)
.Footers(wdHeaderFooterPrimary).PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberLeft, _
FirstPage:=False
End With

C# Code :-

public void PagenumberFooterPrimary()
{
object aligment = Word.WdPageNumberAlignment.wdAlignPageNumberLeft;
object FirstName = false;

ThisApplication.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add(ref aligment, ref FirstName);
}

VBA Code :-

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.PageNumbers(1).Alignment = wdAlignPageNumberCenter

C# Code :-

public void PagenumberAlign()
{
ThisApplication.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers[1].Alignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
}

VBA Code :-

Dim objPages As Pages

Set objPage = ActiveDocument. _
ActiveWindow.Panes(1).Pages

C# Code :-

public void PanePage()
{
Word.Pages objPage = ThisApplication.ActiveDocument.ActiveWindow.Panes[1].Pages;
}

VBA Code :-

Dim objPage As Page

Set objPage = ActiveDocument.ActiveWindow _
.Panes(1).Pages.Item(1)

C# Code :-

public void Pageitem()
{
Word.Page objpage = ThisApplication.ActiveDocument.ActiveWindow.Panes[1].Pages[1];
}

VBA Code :-

ActiveDocument.ActiveWindow.Split = True
For Each aPane In ActiveDocument.ActiveWindow.Panes
aPane.DisplayRulers = False
Next aPane

C# Code :-

public void ActiveWindowPanes()
{
ThisApplication.ActiveDocument.ActiveWindow.Split = true;

Word.Panes wordPanes = ThisApplication.ActiveDocument.ActiveWindow.Panes;

foreach(Word.Pane wordPane in wordPanes)
{
wordPane.DisplayRulers = false;
}

}

VBA Code :-

ActiveDocument.ActiveWindow.Split = True
For Each aPane In ActiveDocument.ActiveWindow.Panes
aPane.DisplayRulers = False
Next aPane

ActiveDocument.ActiveWindow.Panes.Add SplitVertical:=20

C# Code :-

public void ActiveWindowPanes()
{
ThisApplication.ActiveDocument.ActiveWindow.Split = true;

Word.Panes wordPanes = ThisApplication.ActiveDocument.ActiveWindow.Panes;

foreach(Word.Pane wordPane in wordPanes)
{
wordPane.DisplayRulers = false;
}

object SpiltVertical = 20;

ThisApplication.ActiveDocument.ActiveWindow.Panes.Add(ref SpiltVertical);

}
VBA Code :-

ActiveDocument.ActiveWindow.View.Type = wdNormalView
If ActiveDocument.Footnotes.Count >= 1 Then
ActiveDocument.ActiveWindow.View.SplitSpecial = wdPaneFootnotes
response = _
MsgBox("Do you want to close the footnotes pane?", vbYesNo)
If response = vbYes Then _
ActiveDocument.ActiveWindow.ActivePane.Close
End If

C# Code :-

public void SplitSpecial()
{
ThisApplication.ActiveDocument.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdNormalView;

if(ThisApplication.ActiveDocument.Footnotes.Count >= 1 )
{
ThisApplication.ActiveDocument.ActiveWindow.View.SplitSpecial = Microsoft.Office.Interop.Word.WdSpecialPane.wdPaneFootnotes;

}
}

VBA Code :-

With Selection.Paragraphs
.Alignment = wdAlignParagraphRight
.LineSpacingRule = wdLineSpaceDouble
End With

C# Code :-

public void Selectionpara()
{
ThisApplication.Selection.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;

ThisApplication.Selection.Paragraphs.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing
.wdLineSpaceDouble;
}

VBA Code :-

Set pr1 = Selection.Range.SpellingErrors
sc = pr1.Count
Set pr2 = Selection.Range.GrammaticalErrors
gc = pr2.Count
Msgbox "Spelling errors: " & sc & vbCr _
& "Grammatical errors: " & gc

C# Code :-

public void SpellingErrs()
{
Word.ProofreadingErrors proofreadingSpelling = ThisApplication.Selection.Range.SpellingErrors;
int sc = proofreadingSpelling.Count;

Word.ProofreadingErrors proofreadingGrammatical = ThisApplication.Selection.Range.GrammaticalErrors;
int gc = proofreadingGrammatical.Count;

}

VBA Code :-

Set myRange = Selection.Range.SpellingErrors(2)
myRange.Select

Set myRange = Selection.Range.GrammaticalErrors(1)
Msgbox myRange.Text

C# Code :-

public void SpellingandGramm()
{
Word.Range wordRange = ThisApplication.Selection.Range.SpellingErrors[2];
wordRange.Select();

wordRange = ThisApplication.Selection.Range.GrammaticalErrors[1];
wordRange.Select();
}

Sunday, August 1, 2010

Refernce Collection :- (O) Other Correct Exception

VBA Code :-

For Each aCap In AutoCorrect.OtherCorrectionsExceptions
MsgBox aCap.Name
Next aCap

C# Code :-

public void OtherCorrectException()
{
Word.OtherCorrectionsExceptions wordCorrectexception = ThisApplication.AutoCorrect.OtherCorrectionsExceptions;

foreach (Word.OtherCorrectionsException wordOe in wordCorrectexception)
{
string strName = wordOe.Name;
}
}

VBA Code :-

AutoCorrect.OtherCorrectionsExceptions.Add Name:="TipTop"

C# Code :-

public void OtherExcepAdd()
{
string strName = "Tip Top";
ThisApplication.AutoCorrect.OtherCorrectionsExceptions.Add(strName);
}

VBA Code :-

MsgBox AutoCorrect.OtherCorrectionsExceptions(1).Name

C# Code :-

public void OtherExcepObject()
{
object Name = 1;
string strName = ThisApplication.AutoCorrect.OtherCorrectionsExceptions.get_Item(ref Name).Name;
}

Refernce Collection :- (M) MailMergeDataFields , MailMergeFiledName,MailMergeFileds,MappeddataFileds

VBA Coded :-

For Each afield In ActiveDocument.MailMerge.DataSource.DataFields
MsgBox afield.Name
Next afield

C# Code :-

public void MailMergeDataFields()
{
Word.MailMergeDataFields wordMailFileds = ThisApplication.ActiveDocument.MailMerge.DataSource.DataFields;

foreach (Word.MailMergeDataField mailMergeDataFiled in wordMailFileds)
{
string strName = mailMergeDataFiled.Name;
}
}

VBA Code :-

If ActiveDocument.MailMerge.DataSource.Type = _
wdMergeInfoFromWord Then
ActiveDocument.MailMerge.EditDataSource
With ActiveDocument.Tables(1)
.Columns.Add
.Cell(Row:=1, Column:=.Columns.Count).Range.Text = "Author"
End With
End If

C# Code :-

public void MailMergeInfoWord()
{
if (ThisApplication.ActiveDocument.MailMerge.DataSource.Type == Microsoft.Office.Interop.Word.WdMailMergeDataSource.wdMergeInfoFromWord)
{
ThisApplication.ActiveDocument.MailMerge.EditDataSource();
ThisApplication.ActiveDocument.Tables[1].Columns.Add(ref missing).Cells.Add(ref missing).Range.Text = "Avinash";
}
}

VBA Code :-

MsgBox ActiveDocument.MailMerge.DataSource.DataFields(1).Name

C# Code :-

public void MailMergemessage()
{
object findName = 1;
string strName = ThisApplication.ActiveDocument.MailMerge.DataSource.DataFields.get_Item(ref findName).Name;
}

VBA Code :-

For Each afield In ActiveDocument.MailMerge.DataSource.FieldNames
MsgBox afield.Name
Next afield

C# Code :-

public void MailMergeDataFieldNames()
{
Word.MailMergeFieldNames wordMailFileds = ThisApplication.ActiveDocument.MailMerge.DataSource.FieldNames;

foreach (Word.MailMergeFieldName mailMergeDataFiled in wordMailFileds)
{
string strName = mailMergeDataFiled.Name;
}
}

VBA Code :-

Set myMMFields = ActiveDocument.MailMerge.Fields
myMMFields(myMMFields.Count).Select
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdMove
ActiveDocument.MailMerge.Fields.AddAsk Range:=Selection.Range, _
Name:="Name", Prompt:="Type your name", AskOnce:=True

C# Code :-

public void MailMergeFileds()
{
Word.MailMergeFields wordMMF = ThisApplication.ActiveDocument.MailMerge.Fields;

wordMMF[wordMMF.Count].Select();

object Unit = Word.WdUnits.wdWord;
object Count = 1;
object extend = Word.WdMovementType.wdMove;

Word.Range wrange = ThisApplication.Selection.Range;
string AddAskName = "Aviansh";
object prompt = "Type Your name";
object askonce = true;

ThisApplication.Selection.Move(ref Unit, ref Count);

ThisApplication.ActiveDocument.MailMerge.Fields.AddAsk(wrange, AddAskName, ref prompt, ref missing, ref askonce);

}

VBA Code :-

ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, _
Name:="MiddleInitial"

C# Code :-

public void AddMailmergeFileds()
{
Word.Range wrange = ThisApplication.Selection.Range;
string AddAskName = "Aviansh";

ThisApplication.ActiveDocument.MailMerge.Fields.AddAsk(wrange, AddAskName, ref missing, ref missing, ref missing);
}

VBA Code :-

Sub MappedFields()
Dim intCount As Integer
Dim docCurrent As Document
Dim docNew As Document

On Error Resume Next

Set docCurrent = ThisDocument
Set docNew = Documents.Add

'Add leader tab to new document
docNew.Paragraphs.TabStops.Add _
Position:=InchesToPoints(3.5), _
Leader:=wdTabLeaderDots

With docCurrent.MailMerge.DataSource

'Insert heading paragraph for tabbed columns
docNew.Content.InsertAfter "Word Mapped Data Field" _
& vbTab & "Data Source Field"

Do
intCount = intCount + 1

'Insert Word mapped data field name and the
'corresponding data source field name
docNew.Content.InsertAfter .MappedDataFields( _
Index:=intCount).Name & vbTab & _
.MappedDataFields(Index:=intCount) _
.DataFieldName

'Insert paragraph
docNew.Content.InsertParagraphAfter
Loop Until intCount = .MappedDataFields.Count

End With

End Sub

C# Code :-


public void MappedFields()
{


int inCount = 0;
Word.Document docCurrent = null;
Word.Document docNew = null;

docCurrent = ThisApplication.ActiveDocument;
docNew = ThisApplication.Documents.Add(ref missing, ref missing, ref missing, ref missing);


object TabLeaderdots = Word.WdTabLeader.wdTabLeaderDots;
float Postion = 3.5f;
docNew.Paragraphs.TabStops.Add(Postion, ref missing, ref TabLeaderdots);

}

Saturday, July 31, 2010

Refernceing Collection :- (L) Lanuages,Lines,List Entries , Listlevel,List paragraphs , List ,List Collection

VBA Code :-

For Each la In Languages
Msgbox la.NameLocal
Next la

C# Code :-

public void Lang()
{
Word.Languages la = ThisApplication.Languages;

foreach (Word.Language wl in la)
{
string strLocalName = wl.Name;
MessageBox.Show(strLocalName);
}
}

VBA Code :-

Dim objLines As Lines

Set objLines = ActiveDocument.ActiveWindow.Panes(1) _
.Pages(1).Rectangles(1).Lines

C# Code :-

public void ObjLines()
{
Word.Lines objLines = null;
objLines = ThisApplication.ActiveDocument.ActiveWindow.Panes[1].Pages[1].Rectangles[1].Lines;
}

VBA Code :-

Dim objRectangle As Rectangle
Dim objLines As Lines

Set objRectangle = ActiveDocument.ActiveWindow _
.Panes(1).Pages(1).Rectangles(1)

If objRectangle.RectangleType = wdTextRectangle Then _
Set objLines = objRectangle.Lines

C# Code :-

public void RectangleLines()
{
Word.Rectangle objRectangle = null;
Word.Lines objLines = null;
objRectangle = ThisApplication.ActiveDocument.ActiveWindow.Panes[1].Pages[1].Rectangles[1];


if (objRectangle.RectangleType == Microsoft.Office.Interop.Word.WdRectangleType
.wdTextRectangle)
{
objLines = objRectangle.Lines;
}
}

VBA Code :-

For Each le In _
ActiveDocument.FormFields("Drop1").DropDown.ListEntries
MsgBox le.Name
Next le

C# Code :-

public void formFileds()
{

object item = 1;

int i=1;
foreach ( Word.ListEntries listEntries in ThisApplication.ActiveDocument.FormFields.get_Item(ref item).DropDown.ListEntries )
{
object getName = i;
string strName = listEntries.get_Item(ref getName).Name;
i++;

}
}

VBA Code :-

Set myField = _
ActiveDocument.FormFields.Add(Range:=Selection.Range, _
Type:=wdFieldFormDropDown)
With myField.DropDown.ListEntries
.Add Name:="Red"
.Add Name:="Blue"
.Add Name:="Green"
End With

C# Code :-

public void AddFiledSample()
{
Word.Range wordSelection = ThisApplication.Selection.Range;

ThisApplication.ActiveDocument.FormFields.Add(wordSelection, Microsoft.Office.Interop.Word.WdFieldType.wdFieldFormDropDown).DropDown.ListEntries.Add("Red", ref missing);

ThisApplication.ActiveDocument.FormFields.Add(wordSelection, Microsoft.Office.Interop.Word.WdFieldType.wdFieldFormDropDown).DropDown.ListEntries.Add("Blue", ref missing);

ThisApplication.ActiveDocument.FormFields.Add(wordSelection, Microsoft.Office.Interop.Word.WdFieldType.wdFieldFormDropDown).DropDown.ListEntries.Add("Green", ref missing);



}

VBA Code :-

Set mytemp = ActiveDocument.ListTemplates(1)
For Each lev In mytemp.ListLevels
lev.NumberStyle = wdListNumberStyleLowercaseLetter
Next lev

C# Code :-

public void ListofTempltes()
{
object i = 1;

Word.ListTemplates myTemp = ThisApplication.ActiveDocument.ListTemplates;
foreach (Word.ListTemplates lev in myTemp.get_Item(ref i).ListLevels)
{

}

}

VBA Code :-

ActiveDocument.ListTemplates(1).ListLevels(1).StartAt = 4

C# Code :-

public void ListLevelStarts()
{
object objlevel = 1;
Word.ListLevels wl = ThisApplication.ActiveDocument.ListTemplates.get_Item(ref objlevel).ListLevels;
foreach (Word.ListLevel wlevel in wl)
{
wlevel.StartAt = 4;
}
}

VBA Code :-

For Each para in ActiveDocument.ListParagraphs
para.Range.HighlightColorIndex = wdTurquoise
Next para

C# code :-

public void ListParagraph()
{
Word.ListParagraphs wlps = ThisApplication.ActiveDocument.ListParagraphs;

foreach (Word.Paragraph wllps in wlps)
{
wllps.Range.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdTurquoise;
}
}

VBA Code :-

For Each li In ActiveDocument.Lists
MsgBox li.CountNumberedItems
Next li

C# Code :-

public void ListsActive()
{
Word.Lists wordList = ThisApplication.ActiveDocument.Lists;

foreach (Word.List wrdlist in wordList)
{
string strCount =wrdlist.CountNumberedItems(ref missing, ref missing).ToString();
MessageBox.Show(strCount);
}
}

VBA Code :-

Set temp1 = ListGalleries(wdNumberGallery).ListTemplates(1)
ActiveDocument.Lists(2).ApplyListTemplate ListTemplate:=temp1

C# Code :-

public void ListGallies()
{
object indexno =1;

Word.ListGalleries temp1 = ThisApplication.ListGalleries;
Word.ListTemplates wrdlstTemp = temp1[Microsoft.Office.Interop.Word.WdListGalleryType.wdNumberGallery].ListTemplates;

Word.ListTemplate wordtemp = wrdlstTemp.get_Item(ref indexno);

this.Application.ActiveDocument.Lists[2].ApplyListTemplate(wordtemp, ref missing, ref missing);


}

VBA Code :-

For Each lt In ActiveDocument.ListTemplates
MsgBox "This is a multiple-level list template - " _
& lt.OutlineNumbered
Next LT

C# Code :-

public void listTemplate()
{
Word.ListTemplates wrdTemps = ThisApplication.ActiveDocument.ListTemplates;

foreach (Word.Template wrdTemp in wrdTemps)
{
string strname = wrdTemp.Name;
}
}

VBA Code :-

Set myLT = ActiveDocument.ListTemplates.Add
Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=myLT

C# Code :-

public void ActiveListtemo()
{
object numberline =4;
object name ="test";
ThisApplication.ActiveDocument.ListTemplates.Add(ref numberline, ref name);
}

Refernce Collection :-(K) KeyBindings , KeyBound

VBA Code :-

CustomizationContext = NormalTemplate
For Each aKey In KeyBindings
Selection.InsertAfter aKey.Command & vbTab _
& aKey.KeyString & vbCr
Selection.Collapse Direction:=wdCollapseEnd
Next aKey

C# Code :-

public void CustomizationTest()
{
ThisApplication.CustomizationContext = ThisApplication.NormalTemplate;
Word.KeyBindings wordKeyBinding = ThisApplication.KeyBindings;

foreach(Word.KeyBinding wkeybinding in wordKeyBinding)
{
string strText = wkeybinding.Command + " " + wkeybinding.KeyString ;
ThisApplication.Selection.InsertAfter(strText);


object objDir = Word.WdCollapseDirection.wdCollapseEnd ;
ThisApplication.Selection.Collapse(ref objDir);
}
}

VBA Code :-

CustomizationContext = ActiveDocument
KeyBindings.Add KeyCategory:=wdKeyCategoryStyle, _
Command:="Heading 1", _
KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyH)

C# Code :-

public void SpecialKey()
{
ThisApplication.CustomizationContext = ThisApplication.NormalTemplate;
string strCommand = "Heading 1";
Word._Global wrdGlobal = null ;

object wdKeyAlt = Microsoft.Office.Interop.Word.WdKey.wdKeyAlt;
object wdKeyH = Microsoft.Office.Interop.Word.WdKey.wdKeyH;

int keycode = wrdGlobal.BuildKeyCode(Microsoft.Office.Interop.Word.WdKey.wdKeyControl,ref wdKeyAlt,ref wdKeyH, ref missing);


ThisApplication.KeyBindings.Add(Microsoft.Office.Interop.Word.WdKeyCategory.wdKeyCategoryStyle, strCommand, keycode, ref missing, ref missing);
}

VBA Code :-

CustomizationContext = NormalTemplate
For Each myKey In KeysBoundTo(KeyCategory:=wdKeyCategoryCommand, _
Command:="FileNew")
myStr = myStr & myKey.KeyString & vbCr
Next myKey
MsgBox myStr

C# Code :-

public void KeyCatelog()
{
ThisApplication.CustomizationContext = ThisApplication.NormalTemplate;
Word.KeyBindings myKey = ThisApplication.KeyBindings;

foreach (Word.KeyBinding wrdKey in myKey)
{
string mystr = "";
mystr = mystr + wrdKey.KeyString;

}
}

Friday, July 30, 2010

Referncening Collection :- (I) Indexes, Inline Shapes

VBA Code :-

ActiveDocument.Indexes.Format = wdIndexClassic

C# Code :-

public void IndexesFormat()
{
ThisApplication.ActiveDocument.Indexes.Format = Microsoft.Office.Interop.Word.WdIndexFormat.wdIndexClassic;
}

VB A Code :-

Set myRange = ActiveDocument.Content
myRange.Collapse Direction:=wdCollapseEnd
ActiveDocument.Indexes.Add Range:=myRange, Type:=wdIndexRunin

C# Code :-

public void ActiveDocumentContent()
{
Word.Range myRange = ThisApplication.ActiveDocument.Content;
object direction = Word.WdCollapseDirection.wdCollapseEnd;
myRange.Collapse(ref direction);
object wdtype = Word.WdIndexType.wdIndexRunin;
ThisApplication.ActiveDocument.Indexes.Add(myRange, ref missing, ref missing, ref wdtype, ref missing, ref missing, ref missing, ref missing);
}

VBA Code :-

If ActiveDocument.Indexes.Count >= 1 Then
ActiveDocument.Indexes(1).Update
End If

C# Code :-

public void IndexsCount()
{
int indexActiveCount = ThisApplication.ActiveDocument.Indexes.Count;

if (indexActiveCount >= 1)
{
ThisApplication.ActiveDocument.Indexes[1].Update();
}
}

VBA Code :-

For Each iShape In ActiveDocument.InlineShapes
iShape.ConvertToShape
Next iShape

C# Code :-

public void ShapesCount()
{
Word.InlineShapes wordinlineShapes = ThisApplication.ActiveDocument.InlineShapes;

foreach (Word.InlineShape wls in wordinlineShapes)
{
wls.ConvertToShape();
}
}

Refernce Collection :- (F) HangualAndAlphabet, headersFooter, headerStyle, HTMLDIVSION, Hyperlinks

VBA Code :-

For Each aHan In AutoCorrect.HangulAndAlphabetExceptions
MsgBox aHan.Name
Next aHan

C# Code :-

public void HangulAndAlphabetExceptions()
{
Word.HangulAndAlphabetExceptions wordautoCorrect = ThisApplication.AutoCorrect.HangulAndAlphabetExceptions ;

foreach (Word.HangulAndAlphabetException wd in wordautoCorrect)
{
string strHangualExpection = wd.Name;
MessageBox.Show(strHangualExpection);
}
}

VBA Code :-

AutoCorrect.HangulAndAlphabetExceptions.Add Name:="hello

C# Code :-

public void AddHangualAlpaExecption()
{
string strName = "Hello";
ThisApplication.AutoCorrect.HangulAndAlphabetExceptions.Add(strName);
}

VBA Code :-

AutoCorrect.HangulAndAlphabetExceptions("goodbye").Delete

C# Code :-

public void DeleteHangulAlphaExecption()
{
int countHangul = ThisApplication.AutoCorrect.HangulAndAlphabetExceptions.Count;

for(int i = 1 ; i >= countHangul;i++)
{
object hangalCount = i;

string nameHangal = ThisApplication.AutoCorrect.HangulAndAlphabetExceptions.get_Item(ref hangalCount).Name;

if (nameHangal == "goodbye")
{
ThisApplication.AutoCorrect.HangulAndAlphabetExceptions.get_Item(ref hangalCount).Delete();

}

}
}

VBA Code :-

AutoCorrect.HangulAndAlphabetExceptions(1).Name

C# Code :-

public void DeleteHangulAlphaExecption()
{
int countHangul = ThisApplication.AutoCorrect.HangulAndAlphabetExceptions.Count;

for (int i = 1; i >= countHangul; i++)
{
object hangalCount = i;

string nameHangal = ThisApplication.AutoCorrect.HangulAndAlphabetExceptions.get_Item(ref hangalCount).Name;

MessageBox.Show(nameHangal);

}
}

VBA Code :-

With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
If .Range.Text <> vbCr Then
MsgBox .Range.Text
Else
MsgBox "Footer is empty"
End If
End With

C# Code :-

public void HeadersFooter()
{
string strValue ="";
strValue = ThisApplication.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text;
if (strValue == "")
{
MessageBox.Show(strValue);
}
else
{
MessageBox.Show("Footer is Empty");
}

}

VBA Code :-

With ActiveDocument.Sections(1)
.Headers(wdHeaderFooterPrimary).Range.Text = "Header text"
.Footers(wdHeaderFooterPrimary).Range.Text = "Footer text"
End With

C# Code :-

public void HeaderFooterText()
{
ThisApplication.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "Footer text";
ThisApplication.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "Header text";


}

VBA Code :-

With ActiveDocument
.PageSetup.DifferentFirstPageHeaderFooter = True
.Sections(1).Footers(wdHeaderFooterFirstPage) _
.Range.InsertBefore _
"Written by Kate Edson"
End With

C# Code :-

public void DifferentFirstPageHeaderFooter()
{
if (ThisApplication.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter == 1)
{
string strValue = "Written by Avinash Tiwari";
ThisApplication.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range.InsertBefore(strValue);
}
}

VBA Code :-

With ActiveDocument.Sections(1)
.PageSetup.DifferentFirstPageHeaderFooter = True
.Footers(wdHeaderFooterPrimary).PageNumbers.Add _
FirstPage:=True
End With

C# Code :-

public void DifferentFirstPageHeaderFootertest()
{
if (ThisApplication.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter == 1)
{
string strValue = "Written by Avinash Tiwari";
ThisApplication.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.InsertBefore(strValue);
}
}

VBA Code :-

MsgBox ActiveDocument.TablesOfContents(1).HeadingStyles.Count

C# Code :-

public void HeadingStylesCount()
{
int count = ThisApplication.ActiveDocument.TablesOfContents[1].HeadingStyles.Count;

MessageBox.Show(System.Convert.ToString(count));
}

VBA Code :-

Set myToc = ActiveDocument.TablesOfContents.Add _
(Range:=ActiveDocument.Range(0, 0), UseHeadingStyles:=True, _
LowerHeadingLevel:=3, UpperHeadingLevel:=1)
myToc.HeadingStyles.Add Style:="Title", Level:=2

C# Code :-

public void Toc()
{
object start = 0;
object end = 0;
object UseHeaderStyle = true;
object LowerHeadingLevel =3;
object UpperHeadingLevel =1;
Word.Range wordRanges = ThisApplication.ActiveDocument.Range(ref start,ref end);



Word.TableOfContents mttoc = ThisApplication.ActiveDocument.TablesOfContents.Add(wordRanges, ref UseHeaderStyle, ref UpperHeadingLevel, ref UpperHeadingLevel, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

object style = "Title";
short Level = 2;
mttoc.HeadingStyles.Add(ref style, Level);

}

VBA Code :-

Set myTOF = ActiveDocument.TablesOfFigures.Add _
(Range:=ActiveDocument.Range(0, 0), AddedStyles:="Title")
MsgBox myTOF.HeadingStyles(1).Style

C# Code :-

public void TOF()
{ object start = 0;
object end = 0;
Word.Range wordRanges = ThisApplication.ActiveDocument.Range(ref start,ref end);
object AddedStyles = "Title";

Word.TableOfFigures myTOF = ThisApplication.ActiveDocument.TablesOfFigures.Add(wordRanges, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref AddedStyles, ref missing, ref missing);

object prop = 1;
object strMyTOF = myTOF.HeadingStyles[1].get_Style();

}

VBA Code :-

With ActiveDocument.HTMLDivisions
.Add
.Item(Index:=1).Range.Text = "This is a new HTML division."
With .Item(1)
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleTriple
.LineWidth = wdLineWidth025pt
.Color = wdColorRed
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleDot
.LineWidth = wdLineWidth050pt
.Color = wdColorBlue
End With
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleDouble
.LineWidth = wdLineWidth075pt
.Color = wdColorBrightGreen
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleDashDotDot
.LineWidth = wdLineWidth075pt
.Color = wdColorTurquoise
End With
End With
End With

C# Code :-

public void HTMLDivisions()
{
Word.Range wordRange = ThisApplication.Selection.Range;
object mywordRange = wordRange;
ThisApplication.ActiveDocument.HTMLDivisions.Add(ref mywordRange).Range.Text = "This is a new HTML division.";
Word.HTMLDivisions wordHtmlDivisions = ThisApplication.ActiveDocument.HTMLDivisions;
int htmlDivisonsCount = ThisApplication.ActiveDocument.HTMLDivisions.Count;
for(int i =1; i <= htmlDivisonsCount; i++)
{
object htmdiv = i;

///wdBorderBottom
wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleTriple;

wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt;

wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].Color = Microsoft.Office.Interop.Word.WdColor.wdColorRed;


////wdBorderTop
wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleDot;

wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop].Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlue;

////wdBorderLeft

wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleDouble;

wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth075pt;

wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft].Color = Microsoft.Office.Interop.Word.WdColor.wdColorBrightGreen;

//// wdBorderRight


wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleDashDotDot;

wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth075pt;

wordHtmlDivisions[i].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight].Color = Microsoft.Office.Interop.Word.WdColor.wdColorTurquoise;



}
}

VBA Code :-

For Each hLink In Documents(1).Hyperlinks
If InStr(hLink.Address, "Microsoft") <> 0 Then
hLink.Follow
Exit For
End If
Next hLink

C# Code :-

public void HyperLinks()
{
Word.Hyperlinks myHyperLink = ThisApplication.ActiveDocument.Hyperlinks;
int hyperLink = myHyperLink.Count;


for(int i = 1 ; i >= hyperLink; i++)
{
object objAddress = i;

string strAddress = myHyperLink.get_Item(ref objAddress).Address;
if (hyperLink > 0)
{
if (strAddress.Contains("Microsoft"))
{
myHyperLink.get_Item(ref objAddress).Follow(ref missing, ref missing, ref missing,ref missing,ref missing );
}
}
}
}

VBA Code :-

ActiveDocument.Hyperlinks.Add Address:="http://www.msn.com/", _
Anchor:=Selection.Range

C# Code :-

public void ActiveDocumentHyperlinks()
{
object Anchor = ThisApplication.Selection.Range;
object Address = "http://www.msn.com/";
ThisApplication.ActiveDocument.Hyperlinks.Add( Anchor, ref Address, ref missing, ref missing, ref missing, ref missing);
}

VBA Code :-

If Selection.HyperLinks.Count >= 1 Then
Selection.HyperLinks(1).Follow
End If

C# Code :-

public void SelectionHyperlink()
{
int selHyperLinkCount = ThisApplication.Selection.Hyperlinks.Count;

if (selHyperLinkCount >= 1)
{
object hyperLinkFollow = 1;

ThisApplication.Selection.Hyperlinks.get_Item(ref hyperLinkFollow).Follow(ref missing, ref missing, ref missing, ref missing, ref missing);
}
}

Thursday, July 29, 2010

Refernce Collection :- (G) GroupShapes

VBA Code :-

With ActiveDocument.Shapes
.AddShape(msoShapeIsoscelesTriangle, _
10, 10, 100, 100).Name = "shpOne"
.AddShape(msoShapeIsoscelesTriangle, _
150, 10, 100, 100).Name = "shpTwo"
.AddShape(msoShapeIsoscelesTriangle, _
300, 10, 100, 100).Name = "shpThree"
With .Range(Array("shpOne", "shpTwo", "shpThree")).Group
.Fill.PresetTextured msoTextureBlueTissuePaper
.GroupItems(2).Fill.PresetTextured msoTextureGreenMarble
End With
End With

C# Code :-

public void GroupShapeCollection()
{
int typevalue = (int)Microsoft.Office.Core.MsoAutoShapeType.msoShapeIsoscelesTriangle;

ThisApplication.ActiveDocument.Shapes.AddShape(typevalue, 10.0f, 10.0f, 10.0f, 10.0f, ref missing).Name = "ShapeOne";

typevalue = (int)Microsoft.Office.Core.MsoAutoShapeType.msoShapeIsoscelesTriangle;

ThisApplication.ActiveDocument.Shapes.AddShape(typevalue, 150.0f, 10.0f, 100.0f, 100.0f, ref missing).Name = "shpTwo";

ThisApplication.ActiveDocument.Shapes.AddShape(typevalue, 300.0f, 10.0f, 100.0f, 100.0f, ref missing).Name = "shpThree";
///string[] names = new string[3] {"Matt", "Joanne", "Robert"};

string[] names = new string[3] {"ShapeOne","shpTwo","shpThree"};

object rangobj = names;
ThisApplication.ActiveDocument.Shapes.Range(ref rangobj).Group().Fill.PresetTextured(Microsoft.Office.Core.MsoPresetTexture.msoTextureBlueTissuePaper);
object objvalue = 2;

ThisApplication.ActiveDocument.Shapes.Range(ref rangobj).Group().GroupItems.get_Item(ref objvalue).Fill.PresetTextured(Microsoft.Office.Core.MsoPresetTexture.msoTextureGreenMarble);




}

Refernce Collection :- (F) Fileds , File Converter ,First letter Execption,FontNames,Foot Notes,Form fileds,Frames

VBA Code :-

Selection.Fields.Update

C# Code :-

public void FiledsUpdate()
{

ThisApplication.Selection.Fields.Update();
}

VBA Code :-

Selection.Collapse Direction:=wdCollapseStart
Set myField = ActiveDocument.Fields.Add(Range:=Selection.Range, _
Type:=wdFieldDate)
MsgBox myField.Result

C# Code :-

public void SelectionCollpaseDir()
{
object dir = Word.WdCollapseDirection.wdCollapseStart;
ThisApplication.Selection.Collapse(ref dir);
Word.Range range = ThisApplication.Selection.Range;
object wdfileddate = Word.WdFieldType.wdFieldDate;
Word.Field wdFiled = ThisApplication.ActiveDocument.Fields.Add(range, ref wdfileddate, ref missing, ref missing);

string strName = (string)wdFiled.Result;
MessageBox.Show(strName);

}

VBA Code :-

If ActiveDocument.Fields.Count >= 1 Then
MsgBox "Code = " & ActiveDocument.Fields(1).Code & vbCr _
& "Result = " & ActiveDocument.Fields(1).Result & vbCr
End If

C# Code :-

public void ActiveDocumentFileds()
{
int filedCount = ThisApplication.ActiveDocument.Fields.Count;

if (filedCount >= 1)
{
string strCode = ThisApplication.ActiveDocument.Fields[1].Code.ToString();
string strResult = ThisApplication.ActiveDocument.Fields[1].Result.ToString();

MessageBox.Show(strCode);
MessageBox.Show(strResult);

}
}

VBA Code :-

For Each conv In FileConverters
If conv.FormatName = "WordPerfect 6.x" Then
MsgBox "WordPerfect 6.0 converter is installed"
End if
Next conv

C# Code :-

public void FileConverters()
{
Word.FileConverters fileConverts = ThisApplication.FileConverters;

foreach (Word.FileConverter conv in fileConverts)
{
if (conv.FormatName == "WordPerfect 6.x")
{
MessageBox.Show("WordPerfect 6.0 converter is installed");
}
}
}

VBA Code :-

MsgBox FileConverters(1).FormatName

C# Code :-

public void FileConverterFormatname()
{
object objIndex = 1;

string strFileCon = ThisApplication.FileConverters.get_Item(ref objIndex).FormatName;
}

VBA Code :-

For Each aExcept In AutoCorrect.FirstLetterExceptions
If aExcept.Name = "addr." Then aExcept.Delete
Next aExcept

C# Code :-

public void AutoCorrectFirstLetter()
{
Word.AutoCorrect wordAutoCorrect = ThisApplication.AutoCorrect;
foreach (Word.AutoCorrect cdAutoCorrect in wordAutoCorrect.FirstLetterExceptions )
{
string strName = cdAutoCorrect.Application.Name;
}

}

VBA Code :-

MsgBox PortraitFontNames.Count & " fonts available"

For Each aFont In FontNames
ActiveDocument.Range.InsertAfter aFont & vbCr
Next aFont

C# Code :-

public void PortraitFont()
{
int fontCount = 0;
fontCount = this.Application.FontNames.Count;
int i = 0;
foreach (Word.FontNames wdFontName in ThisApplication.FontNames)
{i++;

ThisApplication.ActiveDocument.Range(ref missing, ref missing).InsertAfter(wdFontName.Application.Name );
}
}

VBA Code :-

ActiveDocument.Footnotes.SwapWithEndnotes


Selection.Collapse Direction:=wdCollapseEnd
ActiveDocument.Footnotes.Add Range:=Selection.Range , _
Text:="The Willow Tree, (Lone Creek Press, 1996)."

C# Code :-

public void Footnotes()
{
ThisApplication.ActiveDocument.Footnotes.SwapWithEndnotes();

object directions = Word.WdCollapseDirection.wdCollapseEnd;

ThisApplication.Selection.Collapse(ref directions);
Word.Range range = ThisApplication.Selection.Range;
object strName = "Avinash Tiwari";
ThisApplication.ActiveDocument.Footnotes.Add(range, ref missing,ref strName);
}

VBA Code :-

If Selection.Footnotes.Count >= 1 Then
Selection.Footnotes(1).Reference.Font.ColorIndex = wdRed
End If

C# Code :-

public void SelFootnotes()
{
int countFootNotes = ThisApplication.Selection.Footnotes.Count;


ThisApplication.Selection.Footnotes[1].Reference.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdRed;

}

VBA Code :-

For Each aField In ActiveDocument.FormFields
If aField.Type = wdFieldFormTextInput Then count = count + 1
Next aField
MsgBox "There are " & count & " text boxes in this document"

C# Code :-

public void FormFileds()
{
int wordFileds = ThisApplication.ActiveDocument.FormFields.Count;
for (int wordFiledCount = 1; wordFiledCount >= wordFileds; wordFiledCount++)
{
object inIndex = wordFiledCount;
Word.FormFields wordfiles = ThisApplication.ActiveDocument.FormFields;

if (wordfiles.get_Item(ref inIndex).Type == Microsoft.Office.Interop.Word.WdFieldType.wdFieldFormTextInput)
{

}


}
}

VBA Code :-

Set ffield = ActiveDocument.FormFields.Add( _
Range:=ActiveDocument.Range(Start:=0,End:=0), _
Type:=wdFieldFormCheckBox)
ffield.CheckBox.Value = True

C# Code :-

public void formfiled()
{
Word.Range wordRange = this.Application.Selection.Range;
Word.FormField wf = ThisApplication.ActiveDocument.FormFields.Add(wordRange, Microsoft.Office.Interop.Word.WdFieldType.wdFieldFormCheckBox);
wf.CheckBox.Value = true;
}

VBA Code :-

ActiveDocument.FormFields("Text1").Result = "Don Funk"

C# Code :-

public void FormFileds()
{
object indexNumber =1;
ThisApplication.ActiveDocument.FormFields.get_Item(ref indexNumber).Result = "Avinash";
}

VBA Code :-

For Each aFrame In ActiveDocument.Frames
aFrame.Borders.Enable = False
Next aFrame

C# Code :-

public void FrameDoc()
{
Word.Frames wframe = ThisApplication.ActiveDocument.Frames;

foreach (Word.Frame wf in wframe)
{
wf.Borders.Enable = -1;
}
}

VBA Code :-

ActiveDocument.Frames.Add _
Range:=ActiveDocument.Paragraphs(1).Range

C# Code :-

public void FrameAdd()
{
Word.Range wr = ThisApplication.Selection.Range;

ThisApplication.ActiveDocument.Frames.Add(wr.Paragraphs[1].Range);
}

VBA Code :-

ActiveDocument.Sections(1).Range.Frames(1).TextWrap = True

C# Code :-

public void FrameTextWrap()
{
ThisApplication.ActiveDocument.Sections[1].Range.Frames[1].TextWrap = true;
}

Refernce-Collection :- (E) Editors, Email Signature Entries,Endnotes

VBA Code :-

Dim objEditor As Editor

Set objEditor = Selection.Editors.Add(wdEditorCurrent)

C# Code :-

public void Editor()
{
Word.Editors objEditor = this.Application.Selection.Editors;
object editors = Word.WdEditorType.wdEditorCurrent;
this.Application.Selection.Editors.Add(ref editors);

}

VBA Code :-

Sub NewEmailSignature()
With Application.EmailOptions.EmailSignature
.EmailSignatureEntries.Add "Jeff Smith", Selection.Range
.NewMessageSignature = "Jeff Smith"
End With
End Sub

C# Code :-

public void NewEmailSignature()
{
string name = "Avinash";
this.Application.EmailOptions.EmailSignature.EmailSignatureEntries.Add(name, Application.Selection.Range);

this.Application.EmailOptions.EmailSignature.NewMessageSignature = "Avinash Tiwari";
}

VBA Code :-

ActiveDocument.Endnotes.Location = wdEndOfSection

C# Code :-

public void EndNotesLoc()
{
ThisApplication.ActiveDocument.Endnotes.Location = Microsoft.Office.Interop.Word.WdEndnoteLocation.wdEndOfSection;
}

VBA Code :-

Selection.Collapse Direction:=wdCollapseEnd
ActiveDocument.Endnotes.Add Range:=Selection.Range , _
Text:="The Willow Tree, (Lone Creek Press, 1996)."

C# Code :-

public void CollpaseDir()
{
object Director = Word.WdCollapseDirection.wdCollapseEnd;

ThisApplication.Selection.Collapse(ref Director);


Word.Range range = ThisApplication.Selection.Range;
object text = "The Willow Tree, (Lone Creek Press, 1996).";

ThisApplication.ActiveDocument.Endnotes.Add(range, ref missing, ref text);
}

VB Code :-

If Selection.Endnotes.Count >= 1 Then
Selection.Endnotes(1).Reference.Font.ColorIndex = wdRed
End If

C# Code :-

public void selection()
{
int endNotesCount = ThisApplication.Selection.Endnotes.Count;

if (endNotesCount >= 1)
{
ThisApplication.Selection.Endnotes[1].Reference.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdRed;
}
}

Wednesday, July 28, 2010

Refernce-Collection :- (D) Diagram Nodes,Dialog ,Dictionaries,Document :- Collection

VBA Code :-

Sub FillDiagramNodes()
ActiveDocument.Shapes(1).Diagram.Nodes.SelectAll
Selection.ShapeRange.Fill.Patterned msoPatternSmallConfetti
End Sub

C# Code :-

public void FillDiagramNodes()
{
object objitemid = 1;
ThisApplication.ActiveDocument.Shapes.get_Item(ref objitemid ).Diagram.Nodes.SelectAll();
ThisApplication.Selection.ShapeRange.Fill.Patterned(Microsoft.Office.Core.MsoPatternType.msoPatternSmallConfetti);
}

VBA Code :-

Sub FillDiagramNode()
ActiveDocument.Shapes(1).Diagram.Nodes.Item(1).Delete
End Sub

C# Code :-

public void FillDiagramNode()
{
object objitemid = 1;
ThisApplication.ActiveDocument.Shapes.get_Item(ref objitemid).Diagram.Nodes.Item(objitemid).Delete();
}

VBA Code :-

MsgBox Dialogs.Count

C# Code :-

public void DialogsCount()
{
string strDilogCount = System.Convert.ToString(this.Application.Dialogs.Count);
MessageBox.Show(strDilogCount);
}

VBA Code :-

dlgAnswer = Dialogs(wdDialogFileOpen).Show

C# Code :-

this.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFileOpen].Show(ref missing);

VBA Code :-

For Each d In CustomDictionaries
Msgbox d.Name
Next d

C# Code :-

public void CustomDictionaries()
{
int i = 0;
Word.Dictionaries wd = this.Application.CustomDictionaries;
foreach(Word.Dictionaries d in wd)
{
i++;
object idName = i;
MessageBox.Show(d.get_Item(ref idName).Name);

}
}

VBA Code :-

CustomDictionaries.Add FileName:="MyCustom.dic"

C# Code :-

public void CustomDictAdd()
{
this.Application.CustomDictionaries.Add("MyCDustom.dic");
}

VBA Code :-

With CustomDictionaries
.ClearAll
.Add FileName:= "MyCustom.dic"
.ActiveCustomDictionary = CustomDictionaries(1)
End With

C# Code :-

public void CustomDict()
{
this.Application.CustomDictionaries.ClearAll();
this.Application.CustomDictionaries.Add("MyCUSTOM.dic");
}

VBA Code :-

For Each aDoc In Documents
aName = aName & aDoc.Name & vbCr
Next aDoc
MsgBox aName

C# Code :-


public void aDocument()
{
foreach (Word.Document aDoc in this.Application.Documents)
{
string strName = aDoc.Name;
MessageBox.Show(strName);
}
}

VBA Code :-

Documents.Add

C# Code :-

public void DocumentAdd()
{
object objDoc = "C:\\mydoc.dotx";
ThisApplication.Documents.Add(ref objDoc, ref missing, ref missing, ref missing);
}

VBA Code :-

Documents.Open FileName:="C:\My Documents\Sales.doc"

C# Code :-

public void DocumentOpen()
{
object objDoc = "C:\\mydoc.dotx";
ThisApplication.Documents.Open(ref objDoc, 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, ref missing);

}

VBA Code :-

Documents(1).Activate

C# Code :-

public void DocuActive()
{
object idDoc = 1;
ThisApplication.Documents.get_Item(ref idDoc).Activate();
}

VBA Code :-

For Each doc In Documents
If doc.Name = "Report.doc" Then found = True
Next doc
If found <> True Then
Documents.Open FileName:="C:\Documents\Report.doc"
Else
Documents("Report.doc").Activate
End If

C# Code :-

public void DocumentLoop()
{
int i=0;
foreach (Word.Documents doc in ThisApplication.Documents)
{ i++;
object docid =i;
string strName = doc.get_Item(ref docid).Name;
if (strName == "Report.doc")
{
object objDoc = "C:\\mydoc.dotx";

ThisApplication.Documents.Open(ref objDoc, 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, ref missing);
}
else
{
ThisApplication.Documents.get_Item(ref docid).Activate();
}
}
}

Sunday, July 25, 2010

Reference-Collection:- (C) :- CanvasShapes Collection

VBA Code :-

Sub AddCanvasShapes()
Dim shpCanvas As Shape
Dim shpCanvasShapes As CanvasShapes
Dim shpCnvItem As Shape

'Adds a new canvas to the document
Set shpCanvas = ActiveDocument.Shapes _
.AddCanvas(Left:=100, Top:=75, _
Width:=50, Height:=75)
Set shpCanvasShapes = shpCanvas.CanvasItems

'Adds shapes to the CanvasShapes collection
With shpCanvasShapes
.AddShape Type:=msoShapeRectangle, _
Left:=0, Top:=0, Width:=50, Height:=50
.AddShape Type:=msoShapeOval, _
Left:=5, Top:=5, Width:=40, Height:=40
.AddShape Type:=msoShapeIsoscelesTriangle, _
Left:=0, Top:=25, Width:=50, Height:=50
End With
End Sub

C# Code :-

public void AddCanvasShapes()
{
Word.Shape shpCanvas = null;
Word.CanvasShapes shpCanvasShapes = null;
Word.Shape shpCnvItem = null;

shpCanvas = ThisApplication.ActiveDocument.Shapes.AddCanvas(100f, 75f, 50, 75f, ref missing);
shpCanvasShapes = shpCanvas.CanvasItems;
shpCanvasShapes.AddShape(1, 0f, 0f, 50f, 50f);
shpCanvasShapes.AddShape(2, 0f, 0f, 40f, 40f);
shpCanvasShapes.AddShape(2, 0f, 25f, 50f, 50f);

}

VBA Code :-

Sub CanvasShapeThree()
With ActiveDocument.Shapes(1).CanvasItems(3)
.Line.ForeColor.RGB = RGB(50, 0, 255)
.Fill.ForeColor.RGB = RGB(50, 0, 255)
.Flip msoFlipVertical
End With
End Sub

C#

public void CanvasShapeThree()
{
object shapesid = "1";
object CanvasItem = "3";
Microsoft.Office.Interop.Word.ColorFormat ColorRGB ;

ThisApplication.ActiveDocument.Shapes.get_Item(ref shapesid).CanvasItems.get_Item(ref CanvasItem).Line.ForeColor.RGB = 1;
ThisApplication.ActiveDocument.Shapes.get_Item(ref shapesid).CanvasItems.get_Item(ref CanvasItem).Flip(Microsoft.Office.Core.MsoFlipCmd.msoFlipVertical);
}

VBA Code :-

CaptionLabels.Add Name:="Photo"

C# Code :-

public void CaptionLabel()
{
ThisApplication.CaptionLabels.Add("Photo");

}

VBA Code :-

CaptionLabels("Figure").NumberStyle = _
wdCaptionNumberStyleLowercaseLetter

C# Code :-

public void CaptionLabes()
{
object objindex = 1;
ThisApplication.CaptionLabels.Add("Photo");
ThisApplication.CaptionLabels.get_Item(ref objindex).NumberStyle = Microsoft.Office.Interop.Word.WdCaptionNumberStyle.wdCaptionNumberStyleHindiLetter1;
}

VBA Code :-

ActiveDocument.Tables(1).Rows(1).Cells.Width = 30

C# Code :-

public void TablesCell()
{
ThisApplication.ActiveDocument.Tables[1].Rows[1].Cells.Width = 30;
}

VBA Code :-

num = Selection.Rows(1).Cells.Count

C# Code :-

public void SelRows()
{
int num = 0;
num = ThisApplication.Selection.Rows[1].Cells.Count;
}

VBA Code :-

Set myTable = ActiveDocument.Tables(1)
myTable.Range.Cells.Add BeforeCell:=myTable.Cell(1, 1)

C# Code:-

public void myTable()
{
object beforecell = "1,2";

Word.Table myTable = ThisApplication.ActiveDocument.Tables[1];
myTable.Range.Cells.Add(ref beforecell);
}

VBA Code :-

Set myCell = ActiveDocument.Tables(1).Cell(Row:=1, Column:=2)
myCell.Shading.Texture = wdTexture20Percent

C# Code :-

public void MyCell()
{
int Row = 1;
int Column = 2;

Word.Table myTable = ThisApplication.ActiveDocument.Tables[1];
myTable.Cell( Row, Column);

myTable.Shading.Texture = Microsoft.Office.Interop.Word.WdTextureIndex.wdTexture20Percent;

}

VBA Code :-

Set myTable = ActiveDocument.Tables(1)
Set aColumn = myTable.Columns.Add(BeforeColumn:=myTable.Columns(1))
For Each aCell In aColumn.Cells
aCell.Range.Delete
aCell.Range.InsertAfter num + 1
num = num + 1
Next aCell

C# Code :-

public void DeeleteColumCell()
{
Word.Table myTable = ThisApplication.ActiveDocument.Tables[1];
object col = "1";
object beforeColumn = myTable.Columns.Add(ref col);
Word.Column aColumn = (Word.Column)myTable.Columns.Add(ref beforeColumn);

int num =0;
foreach (Word.Cell aCell in aColumn.Cells)
{num ++;
aCell.Range.Delete(ref missing, ref missing);
aCell.Range.InsertAfter("" + num + 1 + "");
}

}

VBA Code :-

With ActiveDocument
.Paragraphs(1).Range.InsertParagraphAfter
.Paragraphs(2).Range.InsertBefore "New Text"
End With

C# Code :-

public void Charatcertest()
{
ThisApplication.ActiveDocument.Paragraphs[1].Range.InsertAfter("test1");
ThisApplication.ActiveDocument.Paragraphs[2].Range.InsertAfter("New Text");
}

VBA Code :-

MsgBox ActiveDocument.Tables(1).Columns.Count

C# Code :-

MessageBox.Show((string)ThisApplication.ActiveDocument.Tables[1].Columns.Count);

VBA Code :-

Set myTable = ActiveDocument.Tables.Add(Range:=Selection.Range, _
NumRows:=3, NumColumns:=6)
For Each col In myTable.Columns
col.Shading.Texture = 2 + i
i = i + 1
Next col

C# Code :-

public void ActiveTablesAdd()
{
Word.Range wordRange = ThisApplication.Selection.Range;
Word.Table myTable = ThisApplication.ActiveDocument.Tables.Add(wordRange, 3, 6, ref missing, ref missing);


foreach (Word.Column col in myTable.Columns)
{

col.Shading.Texture = Microsoft.Office.Interop.Word.WdTextureIndex.wdTexture15Percent ;

}
}

VBA Code :-

If ActiveDocument.Tables.Count >= 1 Then
Set myTable = ActiveDocument.Tables(1)
myTable.Columns.Add BeforeColumn:=myTable.Columns(1)
myTable.Columns.DistributeWidth
End If

C# Code :-

public void ActiveDocumentTablesCount()
{
int tablecount = ThisApplication.ActiveDocument.Tables.Count;

if (tablecount >= 1)
{
Word.Table myTable = ThisApplication.ActiveDocument.Tables[1];
object BeforeColumn = myTable.Columns[1];
myTable.Columns.Add(ref BeforeColumn);
myTable.Columns.DistributeWidth();
}
}

VBA Code :-

ActiveDocument.Tables(1).Columns(1).Select

C# Code :-

public void ColSelect()
{
ThisApplication.ActiveDocument.Tables[1].Columns[1].Select();
}

VBA Code :-

ActiveDocument.ActiveWindow.View.SplitSpecial = wdPaneComments
ActiveDocument.Comments.ShowBy = "Don Funk"

C# Code :-

public void SplitView()
{
ThisApplication.ActiveWindow.View.SplitSpecial = Microsoft.Office.Interop.Word.WdSpecialPane.wdPaneComments;
ThisApplication.ActiveDocument.Comments.ShowBy = "Avinash Tiwari";
}

VBA Code :-

Selection.Collapse Direction:=wdCollapseEnd
ActiveDocument.Comments.Add Range:=Selection.Range, _
Text:="review this"

C# Code :-

public void Collpasetest()
{
object Director = Word.WdCollapseDirection.wdCollapseEnd;

ThisApplication.Selection.Collapse(ref Director);
ThisApplication.Selection.Text = "Review This";
}

VBA Code :-

MsgBox ActiveDocument.Comments(1).Author

C# Code :-

public void ActiveComments()
{
string strMessage = ThisApplication.ActiveDocument.Comments[1].Author;
MessageBox.Show(strMessage);
}

VBA Code :-

MsgBox Application.MailingLabel.CustomLabels.Count

C# Code :-

public void MailingLable()
{
int strMessage = ThisApplication.MailingLabel.CustomLabels.Count;
MessageBox.Show(strMessage.ToString());
}

VBA Code :-

Set ML = _
Application.MailingLabel.CustomLabels.Add(Name:="My Labels", _
DotMatrix:=False)
ML.PageSize = wdCustomLabelA4

C# Code :-

public void MailingLabel()
{
object DotMatrix = false;
string strName = "My label";
Word.MailingLabel mailLable = ThisApplication.MailingLabel;
mailLable.CustomLabels.Add(strName, ref DotMatrix);

}

VBA Code :-

If Application.MailingLabel.CustomLabels.Count >= 1 Then
MsgBox Application.MailingLabel.CustomLabels(1).Name
End If

C# Code :-

public void AppMailingLablel()
{
if (ThisApplication.MailingLabel.CustomLabels.Count >= 1)
{object indexvalue = 1;
string strCustomLabels = ThisApplication.MailingLabel.CustomLabels.get_Item(ref indexvalue).Name;
}
}

VBA Code :-

Sub AddProps()
With ThisDocument.SmartTags(1)
.Properties.Add Name:="President", Value:=True
MsgBox "The XML code is " & .XML
End With
End Sub

C# Code :-

public void AddProps()
{
object inderxId =1;
ThisDocument mydoc = new ThisDocument();
mydoc.SmartTags.get_Item(ref inderxId).Properties.Add("Avinash", "true");

}

VBA Code :-

Sub ReturnProps()
With ThisDocument.SmartTags(1).Properties(1)
MsgBox "The Smart Tag name is: " & .Name & vbLf & .Value
End With
End Sub

C# Code :-


public void ReturnProps()
{
object inderxId =1;
ThisDocument mydoc = new ThisDocument();
string name = "";
name = mydoc.SmartTags.get_Item(ref inderxId).Properties.get_Item(ref inderxId).Name;
string value = "";
value = mydoc.SmartTags.get_Item(ref inderxId).Properties.get_Item(ref inderxId).Value;
}