Menu

 

Saturday, August 7, 2010

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;

}

}

No comments:

Post a Comment