CrazyEngineers
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Kaustubh Katdare

    AdministratorAug 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 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Mrunalini

    MemberAug 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 😀
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register