Writing a Macro for Ms Word, anyone knows VBA?

Mrunalini
@mrunalini-toKmxn โ€ข Oct 26, 2024

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 ๐Ÿ˜€

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Kaustubh Katdare

    @thebigk • Aug 10, 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-toKmxn • 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 ๐Ÿ˜€