Visual Basic Issue
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Visual Basic Issue

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Question Visual Basic Issue

    I created a macro in order for any word being "Apple" to get switched with Tomato, Banana, Carrot or Melon. Yet the only words that are getting switched for, are the first two words which are Banana and Carrot. Why is this?
    Sub ECHO()


    Randomize
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormat…
    With Selection.Find
    Dim ltr As Variant


    ltr = Array("Banana", "Carrot", "Melon", "Tomato")

    x = 1
    .Text = "Apple"
    If x = 1 Then
    .Replacement.Text = ltr(Rnd)
    End If
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute replace:=wdReplaceAll

    End Sub

    'Im trying to build a macro that would help me at work. There is a lot of repetative stuff. I want to be able to run a macro that will open de document, edit the document with random stuff and print it on a specific time. I figure I start by randomizing some stuff that needs to be edited. If you guys believe this would be easier doing something else rather than VB let me know. I know little but I'm a quick learner. Thanks

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,092

    Re: Visual Basic Issue

    Have a look here on how to use the Rnd function properly :

    http://www.vbforums.com/showthread.php?t=281172

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center