Pages

Showing posts with label using. Show all posts
Showing posts with label using. Show all posts

Sunday, April 20, 2014

How to get Author details from Track Changes using VBA

Word VBA - extract Revision Author information

If you want to know the details of track revisions, for example, Author name etc the following code will help you:

Sub Get_TrackRevision_Author()

Dim oRev As Revision
Dim oRange As Range

-----------------------------------------------------------
Change the line below to suit your needs
-----------------------------------------------------------
Set oRange = Selection.Range

-----------------------------------------------------------
Coded by Shasur for http://.blogspot.com
-----------------------------------------------------------

For Each oRev In oRange.Revisions
MsgBox oRev.Range.Text & " " & oRev.Author
Next oRev


End Sub


The following code provides you more information (like if the comment is inserted / deleted)

If oRev.Type = wdRevisionDelete Then
MsgBox oRev.Range.Text & " deleted by " & oRev.Author
ElseIf oRev.Type = wdRevisionInsert Then
MsgBox oRev.Range.Text & " added by " & oRev.Author
Else
MsgBox oRev.Range.Text & " " & oRev.Author
End If

If you want to know Date of Revision using VBA then the following can be added

MsgBox oRev.Range.Text & " " & oRev.Author & " " & oRev.Date
Read more »

Friday, April 18, 2014

Using SUMPRODUCT to count



Lets look at the example below,

In column C dates and column D the error happened on the day with possible multiple entries.

”how



The requirement is to calculate the number of times error5 occurred after 5/5/2012 and before 5/15/2012. (answer is 5).

”how


Lets put the two dates in A1 and A2. The formula will be 
=SUMPRODUCT((C1:C22>A1)*(C1:C22<A2)*(D1:D22="error5"))


If you do not want enter dates in cells the formula will be 
=SUMPRODUCT(($C$1:$C$22>DATE(2012,5,5))*($C$1:$C$22<DATE(2012,5,15))*($D$1:$D$22="error5"))


Love to have your comments....


Read more »

Thursday, April 17, 2014

Sort Columns of the Table using Word VBA

Sort Word Table columns using Word VBA

The following function uses Selection.Sort, you can try alternative methods if selection is not possible / permissible

Function SortTable()

ActiveDocument.Tables(1).Select()

Selection.Sort(ExcludeHeader:=True, FieldNumber:="Column 1", SortFieldType _

:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, FieldNumber2 _

:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _

wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _

wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _

wdSortSeparateByTabs, SortColumn:=False, CaseSensitive:=False, LanguageID _

:=wdEnglishUS)

Selection.MoveRight(Unit:=wdCharacter, Count:=1)

End Function

The above uses as three column table. Please customize it for your use

See also:

How to use .Net Array.Sort Function in VBA

Case in-sensitive comparison

Read more »

Sunday, April 13, 2014

How to Convert Decimal to Hexadecimal using VBA

How to Convert Decimal to Octal using VBA

Sub Get_Hex_n_OCt_Values()

For i = 0 To 255

Debug.Print i & vbTab & Hex(i) & vbTab & Oct(i)

Next i

End Sub



VBA Decimal to Hexadecimal Conversion
Read more »