Menu

 

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;
}

Sunday, July 18, 2010

Reference-Collection:- (B) :- Bookmarks Collection

VBA Code :-

If ActiveDocument.Bookmarks.Exists("temp") = True Then
ActiveDocument.Bookmarks("temp").Select
End If

C# Code :-

public void BookMarkExists()
{
bool isBookMarkPresent = ThisApplication.ActiveDocument.Bookmarks.Exists("Temp");

if (isBookMarkPresent)
{
object Name = "temp";
ThisApplication.ActiveDocument.Bookmarks.get_Item(ref Name).Select();
}
}

VBA Code :-

ActiveDocument.Bookmarks.Add Name:="temp", Range:=Selection.Range

C# Code :-

public void BookmarksAdd()
{
string Name = "temp";
Word.Range wordrange = ThisApplication.Selection.Range;
object wr = wordrange;

ThisApplication.ActiveDocument.Bookmarks.Add(Name, ref wr);

}

VBA Code :-

ActiveDocument.Paragraphs(1).Borders.Enable = True

C# Code :-

public void BordersEnable()
{
ThisApplication.ActiveDocument.Paragraphs[1].Borders.Enable = 1;
}

VBA Code :-

With ActiveDocument.Paragraphs(1).Borders(wdBorderBottom)
.LineStyle = wdLineStyleDouble
.LineWidth = wdLineWidth025pt
End With

C# Code :-

public void ParaBorder()
{
ThisApplication.ActiveDocument.Paragraphs[1].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleDouble;
ThisApplication.ActiveDocument.Paragraphs[1].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt;
}

VBA Code :-

With Selection.Characters(1)
.Font.Size = 36
.Borders.Enable = True
End With

C# Code :-

public void Characterselection()
{
ThisApplication.Selection.Characters[1].Font.Size = 36;
ThisApplication.Selection.Characters[1].Borders.Enable = 1;
}

VBA Code :-

For Each aBorder In ActiveDocument.Sections(1).Borders
With aBorder
.ArtStyle = wdArtSeattle
.ArtWidth = 20
End With
Next aBorder

C# Code :-

public void sectionBorder()
{
foreach (Word.Border aborder in ThisApplication.ActiveDocument.Sections[1].Borders)
{
aborder.ArtStyle = Microsoft.Office.Interop.Word.WdPageBorderArt.wdArtSeattle;
aborder.ArtWidth = 20;
}
}

VBA Code :-

Dim objBreaks As Breaks

Set objBreaks = ActiveDocument.ActiveWindow _
.Panes(1).Pages(1).Breaks

C# Code :-

Dim objBreaks As Breaks

Set objBreaks = ActiveDocument.ActiveWindow _
.Panes(1).Pages(1).Breaks

Refrence Collections :- (A) :- Addins Collection

VBA Code :-

For Each ad In AddIns
If ad.Installed = True Then
MsgBox ad.Name & " is installed"
Else
MsgBox ad.Name & " is available but not installed"
End If
Next ad

C# Code

public void findaddin()
{



foreach (Word.AddIn ad in this.Application.AddIns)
{
string straddinname = ad.Name;
if (ad.Installed == true)
{
}
else
{
MessageBox.Show(straddinname);
}

}
}

VBA Code :-

AddIns.Add FileName:="C:\Templates\Other\Letter.dot", Install:=True

C# Code :-

public void AddAddins()
{
string FileName = @"C:\Templates\Other\Letter.dot";
object Installed = true;
this.Application.AddIns.Add(FileName, ref Installed);
}

VBA Code :-

Set rac = ActiveDocument.Shapes _
.AddShape(msoShapeRightArrowCallout, 10, 10, 250, 190)
With rac.Adjustments
.Item(1) = 0.5 'adjusts width of text box
.Item(2) = 0.15 'adjusts width of arrow head
.Item(3) = 0.8 'adjusts length of arrow head
.Item(4) = 0.4 'adjusts width of arrow neck
End With

C# Code :-

public void Addjustment()
{

int myvalue = (int)Microsoft.Office.Core.MsoAutoShapeType.msoShapeRightArrowCallout;
Word.Shape rac = this.Application.ActiveDocument.Shapes.AddShape(myvalue, 10.0f, 10.0f, 250.0f, 190.0f, ref missing);
rac.Adjustments[1] = 0.5f;
rac.Adjustments[2] = 0.15f;
rac.Adjustments[3] = 0.8f;
rac.Adjustments[4] = 0.4f;

}

VBA Code :-

For Each autoCap In AutoCaptions
If autoCap.AutoInsert = True Then
MsgBox autoCap.Name & " is configured for auto insert"
End If
Next autoCap

C# Code :-

public void AutocaptionCollection()
{

foreach(Word.AutoCaption autocap in ThisApplication.AddIns.Application.AutoCaptions )
{
if (autocap.AutoInsert == true)
{
MessageBox.Show(autocap.Name);
}
else
{
MessageBox.Show(autocap.Name);
}
}
}

VBA Code :-

AutoCaptions("Microsoft Word Table").CaptionLabel.Name

C# Code :-

public void ReadAutoCaptionIndex()
{
object NameIndex = "Microsoft Word Table";
string name = "";
name = ThisApplication.AddIns.Application.AutoCaptions.get_Item(ref NameIndex).Application.CaptionLabels.Application.Name;
MessageBox.Show(name);
}

VBA Code :-

AutoCaptions(1).Name

C# Code :-

public void ReadAutoCaptionnumericIndex()
{
object NameIndex = "1";
string name = "";
name = ThisApplication.AddIns.Application.AutoCaptions.get_Item(ref NameIndex).Application.CaptionLabels.Application.Name;
MessageBox.Show(name);
}

VBA Code :-

MsgBox AutoCorrect.Entries.Count

C# Code :-

public void countAutoCorrect()
{
int totalCount = this.Application.AutoCorrect.Entries.Count;
MessageBox.Show(totalCount.ToString());
}

VBA Code :-

AutoCorrect.Entries.Add Name:="thier", Value:="their"

C# Code :-

{
string name = "thier";
string value = "their";
this.Application.AutoCorrect.Entries.Add( name, value);
}

VBA Code :-

AutoCorrect.Entries.AddRichText Name:="PMO", Range:=Selection.Range

C# Code :-

public void AddRichText()
{
string name = "thier";
Word.Range wr = this.Application.Selection.Range;
this.Application.AutoCorrect.Entries.AddRichText(name, wr);

}

VBA Code :-

AutoCorrect.Entries("teh").Value = "the"

C# Code :-

public void autocorrctwordIndex()
{
object obValue = "teh";
this.Application.AutoCorrect.Entries.get_Item(ref obValue).Value = "the";
}

VBA Code :-

MsgBox "Name = " & AutoCorrect.Entries(1).Name & vbCr & _
"Value " & AutoCorrect.Entries(1).Value

C# Code :-

public void AutoCorrectEntriesIndex()
{
object Indexvalue = 1;
string strName = this.Application.AutoCorrect.Entries.get_Item(ref Indexvalue).Name;

MessageBox.Show(strName);

string strValue = this.Application.AutoCorrect.Entries.get_Item(ref Indexvalue).Value;
MessageBox.Show(strValue);
}

VBA Code :-

For Each i In NormalTemplate.AutoTextEntries
If LCase(i.Name) = "test" Then MsgBox "AutoText entry exists"
Next i

C# Code :-

public void AutotextEntries()
{

int countAutoTextEntries = ThisApplication.NormalTemplate.AutoTextEntries.Count;


int i = 1;
while (i <= countAutoTextEntries)
{
object objName = i;
string strname = ThisApplication.NormalTemplate.AutoTextEntries.get_Item(ref objName).Name;
if (strname == "test")
{
MessageBox.Show("Text AutoText Entry exists");
}
i++;
}
}

VBA Code :-

NormalTemplate.AutoTextEntries.Add Name:="Blue", _
Range:=Selection.Range

C# Code :-

public void AddAutotextEntries()
{
string name = "Avinash";
Word.Range wr = this.Application.Selection.Range;
ThisApplication.NormalTemplate.AutoTextEntries.Add(name, wr);
}

VBA code :-

NormalTemplate.AutoTextEntries("cName").Value = _
"The Johnson Company"

C# Code :-

public void AutoTextEntries()
{
object cName = "cName";
ThisApplication.NormalTemplate.AutoTextEntries.get_Item(ref cName).Value = "This Avinash Company";
}

VBA Code :-

Set myTemplate = ActiveDocument.AttachedTemplate
MsgBox "Name = " & myTemplate.AutoTextEntries(1).Name & vbCr _
& "Value " & myTemplate.AutoTextEntries(1).Value

C# Code :-

blic void AutotexrEntries()
{
Word.Template myTemplate = (Word.Template)this.Application.ActiveDocument.get_AttachedTemplate();
int mytempcount = myTemplate.AutoTextEntries.Count;

int i = 1;
while (i <= mytempcount)
{
object objName = i;
string strname = ThisApplication.NormalTemplate.AutoTextEntries.get_Item(ref objName).Name;
string strValue = ThisApplication.NormalTemplate.AutoTextEntries.get_Item(ref objName).Value;
i++;

}
}

Acessing Data and Other Application

VBA Code :-

Sub UsingDAOWithWord()
Dim docNew As Document
Dim dbNorthwind As DAO.Database
Dim rdShippers As Recordset
Dim intRecords As Integer

Set docNew = Documents.Add
Set dbNorthwind = OpenDatabase _
(Name:="C:\Program Files\Microsoft Office\Office11\" _
& "Samples\Northwind.mdb")
Set rdShippers = dbNorthwind.OpenRecordset(Name:="Shippers")
For intRecords = 0 To rdShippers.RecordCount - 1
docNew.Content.InsertAfter Text:=rdShippers.Fields(1).Value
rdShippers.MoveNext
docNew.Content.InsertParagraphAfter
Next intRecords
rdShippers.Close
dbNorthwind.Close
End Sub

C# Code :-

public void UsingDAOWithWord()
{
///Download Northwind from
///http://www.microsoft.com/downloads/en/confirmation.aspx?familyId=c6661372-8dbe-422b-8676-c632d66c529c&displayLang=en
///if donot have

string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\\Database\\Nwind.mdb";
DataSet myDataSet = new DataSet();
OleDbConnection myAccessConn = null;
string strAccessSelect = "select * from Shippers";
Word.Range rngFirstParagraph;

rngFirstParagraph = ThisApplication.ActiveDocument.Paragraphs[1].Range;
try
{
myAccessConn = new OleDbConnection(strAccessConn);
}
catch (Exception ex)
{

rngFirstParagraph.InsertAfter(String.Format( "Error: Failed to create a database connection. \n{0}" , ex.Message));
return;
}


try
{

OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);

myAccessConn.Open();
myDataAdapter.Fill(myDataSet, "Shippers");

}
catch (Exception ex)
{
rngFirstParagraph.InsertAfter(String.Format("Error: Failed to retrieve the required data from the DataBase.\n{0}", ex.Message));
return;
}
finally
{
myAccessConn.Close();
}

DataRowCollection dra = myDataSet.Tables["Shippers"].Rows;
foreach (DataRow dr in dra)
{
// Print the CategoryID as a subscript, then the CategoryName:
rngFirstParagraph.InsertAfter(String.Format("ShippersValue[{0}] is {1}", dr[0], dr[1]));
rngFirstParagraph.InsertParagraphAfter();
}



}

Friday, July 9, 2010

Wordking with Controls and DialogBox

VBA Code :-

Private Sub GetUserName()
With UserForm1
.lstRegions.AddItem "North"
.lstRegions.AddItem "South"
.lstRegions.AddItem "East"
.lstRegions.AddItem "West"
.txtSalesPersonID.Text = "00000"
.Show
' ...
End With
End Sub

C# Code :-

Add Form Name "UserForm1"

Create 2 public Method

public void AddItemtolIst(string value)
{
lstRegions.Items.Add(value);
}

public void AddItemToText(string strvalue)
{
txtSalesPersonID.Text = strvalue;
}

and Now acess that in ThisDocument file..

private void GetUserName()
{
UserForm1 UF = new UserForm1();

UF.AddItemtolIst("North");
UF.AddItemtolIst("South");
UF.AddItemtolIst("East");
UF.AddItemtolIst("West");

UF.AddItemToText("Avinash");
}

VBA Code :-

'Code in module to declare public variables
Public strRegion As String
Public intSalesPersonID As Integer
Public blnCancelled As Boolean

'Code in form
Private Sub cmdCancel_Click()
Module1.blnCancelled = True
Unload Me
End Sub

Private Sub cmdOK_Click()
'Save data
intSalesPersonID = txtSalesPersonID.Text
strRegion = lstRegions.List(lstRegions.ListIndex)
Module1.blnCancelled = False
Unload Me
End Sub

Sub LaunchSalesPersonForm()
frmSalesPeople.Show
If blnCancelled = True Then
MsgBox "Operation Cancelled!", vbExclamation
Else
MsgBox "The Salesperson's ID is: " & _
intSalesPersonID & _
"The Region is: " & strRegion
End If
End Sub

C# Code :-

public string strRegion;
public int intSalesPersonId = 0;
public bool blnCancelled;

private void cmdCancel_Click()
{
blnCancelled = true;
UserForm1 uf = new UserForm1();
uf.Close();
}

private void cmdOK_Click()
{
intSalesPersonId = Convert.ToInt16(txtSalesPersonID.Text);

strRegion = lstRegions.Text;
blnCancelled = false;

UserForm1 uf = new UserForm1();
uf.Close();

}

public void LaunchSalesPersonForm()
{
UserForm1 uf = new UserForm1();
uf.Show();
if (blnCancelled == true)
{
MessageBox.Show("Operation Cancelled !");
}
else
{
MessageBox.Show("The Salesperson's ID is: " + intSalesPersonId + "The Region is: " + strRegion);
}
}

VBA Code :-

Sub ShowOpenDialog()
Dialogs(wdDialogFileOpen).Show
End Sub

C# Code :-

public void ShowOpenDialog()
{

int intvalue = ThisApplication.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFileOpen].Show(ref missing);
}

VBA Code :-

Sub ShowPrintDialog()
Dialogs(wdDialogFilePrint).Show
End Sub

C# Code : -

public void ShowPrintDialog()
{
int intvalue = ThisApplication.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint].Show(ref missing);
}

VBA Code :-

Sub ShowBorderDialog()
With Dialogs(wdDialogFormatBordersAndShading)
.DefaultTab = wdDialogFormatBordersAndShadingTabPageBorder
.Show
End With
End Sub

C# Code :-

public void ShowBorderDialog()
{
ThisApplication.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFormatBordersAndShading].DefaultTab = Word.WdWordDialogTab.wdDialogFormatBordersAndShadingTabPageBorder;
int intvalue = ThisApplication.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFormatBordersAndShading].Show(ref missing);

}

VBA Code :-

Sub DisplayUserInfoDialog()
With Dialogs(wdDialogToolsOptionsUserInfo)
.Display
MsgBox .Name
End With
End Sub

C# Code :-

public void DisplayUserInfoDialog()
{
string strvalue = ThisApplication.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogToolsOptionsUserInfo].Application.UserName ;

MessageBox.Show(strvalue);
}

VBA Coded :-

Sub DisplayUserInfo()
MsgBox Application.UserName
End Sub

C# Code :-

public void DisplayUserInfo()
{
String strvalue = ThisApplication.UserName;
}

VBA Code :-

Sub ShowAndSetUserInfoDialogBox()
With Dialogs(wdDialogToolsOptionsUserInfo)
.Display
If .Name <> "" Then .Execute
End With
End Sub

C# Code :-

public void ShowAndSetUserInfoDialogBox()
{
ThisApplication.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogToolsOptionsUserInfo].Display(ref missing);
ThisApplication.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogToolsOptionsUserInfo].Execute();

}

VBA Code :-

Sub SetUserName()
Application.UserName = "Jeff Smith"
Dialogs(wdDialogToolsOptionsUserInfo).Display
End Sub

C# Code :-

public void SetUserName()
{
ThisApplication.Application.UserName = "Jeff Smith";
ThisApplication.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogToolsOptionsUserInfo].Display(ref missing);
}

VBA Code :-

Sub ShowRightIndent()
Dim dlgParagraph As Dialog
Set dlgParagraph = Dialogs(wdDialogFormatParagraph)
MsgBox "Right indent = " & dlgParagraph.RightIndent
End Sub

C# Code :-

public void ShowRightIndent()
{
Word.Dialog dlgParagraph = null;
dlgParagraph = ThisApplication.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFormatParagraph];

}

VBA Code :-

Sub ShowRightIndexForSelectedParagraph()
MsgBox Selection.ParagraphFormat.RightIndent
End Sub

C# Code :-

public void ShowRightIndexForSelectedParagraph()
{
ThisApplication.Selection.ParagraphFormat.RightIndent = 0.5f;

}

VBA Code :-

Sub SetKeepWithNextForSelectedParagraph()
Selection.ParagraphFormat.KeepWithNext = True
End Sub

C# Code :-

public void SetKeepWithNextForSelectedParagraph()
{
ThisApplication.Selection.ParagraphFormat.KeepWithNext = 1;
}

Wednesday, July 7, 2010

Working With The Word Object

Know Working with The Word Object:-

VBA Code

Set Range1 = ActiveDocument.Words(1)
Set Range2 = ActiveDocument.Words(2)

C# Code

Word.Range Myrange = null;
Myrange = this.Application.ActiveDocument.Words[1];

Word.Range Myrange1 = null;
Myrange1 = this.Application.ActiveDocument.Words[2];

VBA Code

Set Range2 = Range1

C# Code

Word.Range Myrange = null;
Myrange = this.Application.ActiveDocument.Words[1];

Word.Range Myrange1 = null;

Myrange1 = Myrange;

VBA Code:-

Sub CopyWord()
Selection.Words(1).Copy
End Sub

C# Code :-

public void CopyWord()
{
Word.Selection myselection = this.Application.Selection;
myselection.Words[1].Copy();
}

VBA Code :-

Sub CopyParagraph()
ActiveDocument.Paragraphs(1).Range.Copy
End Sub

C# Code :-

public void CopyParagraph()
{
ThisApplication.Application.ActiveDocument.Paragraphs[1].Range.Copy();
}

VBA Code :-

Sub ChangeCase()
ActiveDocument.Words(1).Case = wdUpperCase
End Sub

C# Code :-

public void ChnageCase()
{
this.Application.ActiveDocument.Words[1].Case = Word.WdCharacterCase.wdUpperCase;
}

VBA Code :-

Sub ChangeSectionMargin()
Selection.Sections(1).PageSetup.BottomMargin = InchesToPoints(0.5)
End Sub

C# Code :-

public void ChangeSectionMargin()
{
this.Application.Selection.Sections[1].PageSetup.BottomMargin = this.Application.InchesToPoints(0.5f);
}

VBA Code :-

Sub DoubleSpaceDocument()
ActiveDocument.Content.ParagraphFormat.Space2
End Sub

C# Code :-

public void DoubleSpaceDocument()
{
this.Application.ActiveDocument.Content.ParagraphFormat.Space2();
}

VBA Code :-

Sub SetRangeForFirstTenCharacters()
Dim rngTenCharacters As Range
Set rngTenCharacters = ActiveDocument.Range(Start:=0, End:=10)
End Sub

C# Code :-

public void SetRangeForFirstTenCharacters()
{
Word.Range rngTenCharacters = null;

object start = 0;
object last = 10;
rngTenCharacters = this.Application.ActiveDocument.Range (ref start, ref last);
}

VBA Code :-

Sub SetRangeForFirstThreeWords()
Dim docActive As Document
Dim rngThreeWords As Range
Set docActive = ActiveDocument
Set rngThreeWords = docActive.Range(Start:=docActive.Words(1).Start, _
End:=docActive.Words(3).End)
End Sub

C# Code

public void SetRangeForFirstThreeWords()
{
Word.Document docActive = null;
Word.Range rngThreeeword = null;

docActive = this.Application.ActiveDocument;
object start = docActive.Words[1].Start;
object last = docActive.Words[1].End ;
rngThreeeword = docActive.Range(ref start, ref last);
}

VBA Code :-

ub SetParagraphRange()
Dim docActive As Document
Dim rngParagraphs As Range
Set docActive = ActiveDocument
Set rngParagraphs = docActive.Range(Start:=docActive.Paragraphs(2).Range.Start, _
End:=docActive.Paragraphs(3).Range.End)
End Sub

C# Code :-

public void SetParagraphRange()
{
Word.Document docActive = null;
Word.Range rngThreeeword = null;

docActive = this.Application.ActiveDocument;
object start = docActive.Words[1].Start;
object last = docActive.Paragraphs[1].End;
rngThreeeword = docActive.Range(ref start, ref last);
}

VBA Code :-

Sub BorderAroundFirstParagraph()
Selection.Paragraphs(1).Borders.Enable = True
End Sub

C# Code :-

public void BorderAroundFirstParagraph()
{
this.Application.Selection.Paragraphs[1].Borders.Enable = true;
}

VBA Code :-

Sub ShadeTableRow()
Selection.Tables(1).Rows(1).Shading.Texture = wdTexture10Percent
End Sub

C# Code :-

public void BorderAroundSelection()
{
this.Application.Selection.Tables[1].Rows[1].Shading.Texture = Microsoft.Office.Interop.Word.WdTextureIndex.wdTexture10Percent;
}

VBA Code :-

Sub ShadeTableRow()
If Selection.Tables.Count >= 1 Then
Selection.Tables(1).Rows(1).Shading.Texture = wdTexture25Percent
Else
MsgBox "Selection doesn't include a table"
End If
End Sub

C# Code :-

public void ShadeTableRow()
{
if (this.Application.Selection.Tables.Count >= 1)
{
this.Application.Selection.Tables[1].Rows.Shading.Texture = Microsoft.Office.Interop.Word.WdTextureIndex.wdTexture25Percent;
}
else
{
MessageBox.Show("Selection doesn't include a table");
}
}

VBA Code :-

Sub ShadeAllFirstRowsInTables()
Dim tblTable As Table
If Selection.Tables.Count >= 1 Then
For Each tblTable In Selection.Tables
tblTable.Rows(1).Shading.Texture = wdTexture30Percent
Next tblTable
End If
End Sub

C# Code :-

public void ShadeAllFirstRowsInTables()
{
Word.Table tblTable = null;

if (this.Application.Selection.Tables.Count >= 1)
{
foreach(Word.Table tblTableloop in this.Application.Selection.Tables)
{
tblTableloop.Rows[1].Shading.Texture = Microsoft.Office.Interop.Word.WdTextureIndex.wdTexture30Percent;
}
}
}