View Single Post
 
Old 05-24-2016, 05:26 AM
macdadi112 macdadi112 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: May 2016
Posts: 6
macdadi112 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Random.org provides a simple way of sorting lists, so with the aid of that web site and a couple of Word macros you can easily achieve the required end result

Code:
Option Explicit
Private pWebAddress As String
#If Win64 Then
    Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
                                                                                          ByVal lpOperation As String, ByVal lpFile As String, _
                                                                                          ByVal lpParameters As String, ByVal lpDirectory As String, _
                                                                                          ByVal nShowCmd As Long) As Long
#Else
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
                                                                                  ByVal lpOperation As String, ByVal lpFile As String, _
                                                                                  ByVal lpParameters As String, ByVal lpDirectory As String, _
                                                                                  ByVal nShowCmd As Long) As Long
#End If

Sub Macro1()
Dim dList As New DataObject
Dim orng As Range
    Set orng = ActiveDocument.Range
    orng.Style = "Normal"
    With orng.Find
        Do While .Execute(FindText:=Chr(11), ReplaceWith:=Chr(13))
            orng.Collapse 0
        Loop
    End With
    Set orng = ActiveDocument.Range
    With orng.Find
        Do While .Execute(FindText:=", ", ReplaceWith:=Chr(13))
            orng.Collapse 0
        Loop
    End With
    dList.SetText ActiveDocument.Range.Text
    dList.PutInClipboard
    MsgBox "Now paste the clipboard content to https://www.random.org/lists/." & _
           "Copy the result to the clipboard and run Macro2"
    Call NewShell("https://www.random.org/lists/", 3)
lbl_Exit:
    Set orng = Nothing
    Set dList = Nothing
    Exit Sub
End Sub

Sub Macro2()
Dim oPara As Paragraph
Dim i As Long
    ActiveDocument.Range.Paste
    ActiveDocument.Range.Style = "Normal"
    For i = 1 To ActiveDocument.Paragraphs.Count / 2
        Set oPara = ActiveDocument.Paragraphs(i)
        If LCase(oPara.Range.Characters(1)) = "a" Or _
           LCase(oPara.Range.Characters(1)) = "e" Then
            oPara.Range = Replace(oPara.Range, Chr(13), ", ")
            'or without the comma as in your sample
            'oPara.Range = Replace(oPara.Range, Chr(13), ", ")
        End If
    Next i
lbl_Exit:
    Set oPara = Nothing
    Exit Sub
End Sub

Private Sub NewShell(cmdLine As String, lngWindowHndl As Long)
    ShellExecute lngWindowHndl, "open", cmdLine, "", "", 1
lbl_Exit:
    Exit Sub
End Sub
It doesn't seem to work.

Is it not possible that one script will work??
Reply With Quote