Menu

 

Friday, July 30, 2010

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

No comments:

Post a Comment