Hi
I need to build a dynamic list of available files and display each filename to the user for selection. Once the desired number of files are selected, the user presses OK. It then process the selected files.
Is there a way I can show a list of file with checkboxes next to them? Is there a control available to do something similar? The number of files could be 100 or more :-(.
If above is not possible, can some think of a way to present a list of filenames which the user can select for processing?
Thanks.
Robie
Listbox (I think) with checkbox for each list item
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Listbox (I think) with checkbox for each list item
You could just use the standard Open dialog and allow users to select multiple files using SHIFT/CTRL.
The dialog can be programmed to open at a specific location using ChDir, and it can filter for only word files.
The dialog can be programmed to open at a specific location using ChDir, and it can filter for only word files.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Listbox (I think) with checkbox for each list item
If you can't use the standard dialog, you can use an ActiveX list box inside the document, or a list box on a userform (created in the Visual Basic Editor), and set its MultiSelect property 1 - fmMultiSelectMulti or to 2 - fmMultiSelectExtended. 1 lets the user select / deselect single entries by clicking. 2 lets them select multiple entries the same way you select files in Windows Explorer.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Listbox (I think) with checkbox for each list item
How's that for thinking out the box? Very interesting idea Rudi. Thanks for changing my thought patten - seems a better solution than userform.Rudi wrote:You could just use the standard Open dialog and allow users to select multiple files using SHIFT/CTRL.
The dialog can be programmed to open at a specific location using ChDir, and it can filter for only word files.
Two questions:
1. Can I show OK/Move/Process/... instead of standard Open in the dialog?
2. How would I know which files have been selected?
Thanks.
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Listbox (I think) with checkbox for each list item
For example:
Code: Select all
Sub Test()
Dim i As Long
Dim strFile As String
With Application.FileDialog(1) ' msoFileDialogOpen
.AllowMultiSelect = True
.Filters.Clear
.Filters.Add "All files (*.*)", "*.*"
If .Show Then
For i = 1 To .SelectedItems.Count
strFile = .SelectedItems(i)
' strFile contains the full path and filename
' Your code goes here
Next i
Else
MsgBox "No file(s) selected!", vbExclamation
End If
End With
End Sub
Best wishes,
Hans
Hans
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Listbox (I think) with checkbox for each list item
Here is a version to compile a list of files the user selected into an array...
The macro adds the path and file selected by the user to the active document.
The code might not be completely correct or optimised as I have limited experience with Word VBA (VERY frustrating object library!!!)
The macro adds the path and file selected by the user to the active document.
The code might not be completely correct or optimised as I have limited experience with Word VBA (VERY frustrating object library!!!)
Code: Select all
Sub OpenMultiDocs()
Dim i As Long
Dim strFile As String
Dim Counter As Long
'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)
With Application.FileDialog(1) ' msoFileDialogOpen
.AllowMultiSelect = True
.Filters.Clear
.Filters.Add "Word files (*.doc*)", "*.doc*" '"All files (*.*)", "*.*"
If .Show Then
For i = 1 To .SelectedItems.Count
strFile = .SelectedItems(i)
DirectoryListArray(Counter) = strFile
Counter = Counter + 1
Next i
ReDim Preserve DirectoryListArray(Counter - 1)
Else
MsgBox "No file(s) selected!", vbExclamation
End If
End With
For i = LBound(DirectoryListArray) To UBound(DirectoryListArray)
Selection.EndKey Unit:=wdStory
Selection.MoveEnd Unit:=wdParagraph, Count:=1
Selection.TypeParagraph
ActiveDocument.Range.InsertAfter DirectoryListArray(i)
Next i
End Sub
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Listbox (I think) with checkbox for each list item
Wow.
Excelent Hans and Rudi. You have given me something to work with. I should be able to carry on from here but will call on your expertise if required.
Thank you so much. My manager is really pleased when I said I may have a potential solution to this.
Excelent Hans and Rudi. You have given me something to work with. I should be able to carry on from here but will call on your expertise if required.
Thank you so much. My manager is really pleased when I said I may have a potential solution to this.
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Listbox (I think) with checkbox for each list item
An addendum to the previous query.
1. Is there any way I can access the Word document properties (selected using the above methods) *without* opening the document? Should I even worry about such a thing (only reason for asking this question is some of the document could be huge)?
If not, I can always open the document (one at a time) in the invisible mode to get the properties.
Thanks.
Robie
1. Is there any way I can access the Word document properties (selected using the above methods) *without* opening the document? Should I even worry about such a thing (only reason for asking this question is some of the document could be huge)?
If not, I can always open the document (one at a time) in the invisible mode to get the properties.
Thanks.
Robie
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Listbox (I think) with checkbox for each list item
Here is a starting point. The code uses active document, so I'm not sure if you can access properties from a closed document.
I cannot confirm that now as I am on my way out...
See this for starters...
I cannot confirm that now as I am on my way out...
See this for starters...
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.