View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12832 Members
Join this group to post and comment.
Mrunalini
Mrunalini • Aug 11, 2008

Writing a Macro for Ms Word, anyone knows VBA?

Hi again..

Does any one among you know VBA?
Actually I am writing a Macro for Ms Word, and am stuck up.
If any one knows VBA please let me know..

Always there,
Mrunalini 😀
Kaustubh Katdare
Kaustubh Katdare • Aug 11, 2008
I'm sure we've big number of CEans who know VB. Could you post the details of macro you're trying to write and tell us where you're stuck?

That should help us help you 😀
Mrunalini
Mrunalini • Aug 11, 2008
Thanks for a reply..

I am writing a VBA application which scans the entire document.
While scanning if it comes across any font which is not Times New Roman, it takes the user to that particular location.

The code is as follows:

Sub functionxyz1()
Selection.HomeKey Unit:=wdStory
For i = 1 To ActiveDocument.ComputeStatistics(Statistic:=wdStatisticLines)
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
If Selection.Font.Name <> "Times New Roman" Then
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Font_Change.Show
End If
Next i
End Sub


The user form Font_Change has 2 buttons "Ok and Canel"
If the user clicks on Ok.. it converts the font to Times New Roman, if cancel, then the font is not changed.

The code behind Ok is:
Private Sub Ok_Command_Click()
With Selection.Font
.Name = "Times New Roman"
.Size = 10
Unload Me
End With
End Sub

and behind cancel is:

Private Sub Cancel_Command_Click()
Unload Me
End Sub


Now, the problem is that, the above code Moves down and selects the next text as well, so when I run the Macro on a document, say I Cancel to change the font on the 1st line, but I want to change the font on line 2. But according to the code both the lines are selected (as I'm using MoveDown), and so the font for both the lines are changed.
But actually this not the thing that I need..


Please help me, and let me know where I've gone wrong..
Waiting for a reply and kind suggestions if any.

Thanks
Mrunalini 😀

Share this content on your social channels -