View Single Post
 
Old 08-07-2011, 02:22 AM
ACA ACA is offline Windows 7 Office 2007
Advanced Beginner
 
Join Date: Aug 2010
Posts: 31
ACA is on a distinguished road
Default Opening a file with FileDialogFilePicker

As part of a macro, I have the code below to open documents, and it works O.K.

However, I understand this code is originally meant to filter and select several files, and so it includes a “For Next” loop.
But I don’t need such a loop, as I open just one file each time I run the macro.

The trouble is the relevant line inside the loop, by itself, hasn't got the correct syntax; it must be altered in some way that I don’t know.
Any help with just that, please, or suggestions for an alternative method? Thanks a lot.

Note. I first sent this query to the general Word forum, which was probably not the proper one; I hope it’s not against the rules to shift it to this one.
ACA

Code:
 
Sub Macro1()
'
' Macro1 Macro
 
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
 
Dim vrtSelectedItem As Variant
fd.Filters.Clear
If fd.Show = True Then
 
For Each vrtSelectedItem In fd.SelectedItems
Documents.Open FileName:=vrtSelectedItem ‘How must this line be altered so that it'll work by itself, without the loop?.
Next vrtSelectedItem
 
End If
End Sub

Last edited by ACA; 08-07-2011 at 12:49 PM. Reason: I intended to mark this as 'Solved', but I cannot find how to do that
Reply With Quote