Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2016, 09:27 PM
gmayor's Avatar
gmayor gmayor is offline Getting Files from list and jumbles them Windows 10 Getting Files from list and jumbles them Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #2  
Old 05-24-2016, 04:29 AM
gmaxey gmaxey is offline Getting Files from list and jumbles them Windows 7 32bit Getting Files from list and jumbles them Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

You may need to add a reference to Microsoft Forms. 2.0 object library in order to use the DataObject.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 05-24-2016, 05:26 AM
macdadi112 macdadi112 is offline Getting Files from list and jumbles them Windows 7 64bit Getting Files from list and jumbles them Office 2010 64bit
Novice
Getting Files from list and jumbles them
 
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Files from list and jumbles them list of Opened excel files SDondeti Word VBA 10 05-10-2018 03:52 PM
Change multiple word Files Recipient List (excel) timpvf Mail Merge 0 03-12-2015 11:49 AM
Insert Multiple files - from a list rpothen Word VBA 1 08-28-2014 02:35 AM
list folders and files using .vbs file josianne Excel Programming 3 08-18-2014 03:03 PM
The powerpoint icon on the task bar hides pptx files in the recent files list Innovationgame PowerPoint 0 11-13-2013 09:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:00 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft