FolderPicker

EMONTES149

New Member
Joined
Dec 20, 2016
Messages
8
i am trying to automate the selection of 300 master documents into a project specific directory. The directory path changes per project, so it is important that the end user selects the folder. I am in word and am trying to use the msoFileDialogFolderPicker to select the current directory. It works well with "msoFiuleDialogFilePicker" but I have to select a file for the rest of the code to work. I would rather have the end user select the folder and not have to select a file. I would appreciate any help I can get. I am not a programmer, just an architect trying to be one.

Below is the code I am using.

Sub CreatingRelativeSubDocuments()

Dim fldr As FileDialog

With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
On Error Resume Next
FolderName = .SelectedItems(1)
Err.Clear
On Error GoTo 0
End With

Set fldr = Application.FileDialog(msoFileDialogFolderPicker)

ActiveWindow.ActivePane.View.Type = wdOutlineView

If ActiveWindow.View = wdMasterView Then
ActiveWindow.View = wdOutlineView
Else
ActiveWindow.View = wdMasterView
End If

Selection.Range.Subdocuments.AddFromFile Name:="011000 - summary.docx"
Selection.Range.Subdocuments.AddFromFile Name:="012100 - allowances.docx"
Selection.Range.Subdocuments.AddFromFile Name:="012200 - unit prices.docx"
Selection.Range.Subdocuments.AddFromFile Name:="012200 - unit prices.docx"
Selection.Range.Subdocuments.AddFromFile Name:="012300 - alternates.docx"
Selection.Range.Subdocuments.AddFromFile Name:="013100 - Project Management and Coordination.docx"
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I recommend using "FileSystemObject" to crawl through files because you can do so in an object oriented manner.

Play with this code:

Code:
Public fs As Object
Dim Ofolder As Object
Dim Ofile As Object

If fs Is Nothing Then Set fs = CreateObject("Scripting.FileSystemObject")

Set Ofolder = fs.GetFolder(FolderName)

For Each Ofile In Ofolder.Files[INDENT]Selection.Range.Subdocuments.AddFromFile Name:=Ofile.Name
[/INDENT]
Next

This will hit every file in the folder so you either need to control what is in that folder or you need to add logic to exclude entries that you want to skip
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top