Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 08-07-2011, 02:22 AM
ACA ACA is offline Windows 7 Office 2007
Novice
 
Join Date: Aug 2010
Posts: 16
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 dont 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 dont 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 its 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
  #2  
Old 08-07-2011, 08:27 AM
gmaxey gmaxey is offline Windows XP Office 2010 (Version 14.0)
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 755
gmaxey will become famous soon enough
Default

Sub Macro1()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Filters.Clear
fd.AllowMultiSelect = False
If fd.Show = True Then
Documents.Open FileName:=fd.SelectedItems(1)
End If
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-07-2011, 12:43 PM
ACA ACA is offline Windows 7 Office 2007
Novice
 
Join Date: Aug 2010
Posts: 16
ACA is on a distinguished road
Default

Thank you very much, gmaxey. This is it; exactly what I wanted.
I'm marking this thread 'Solved' and add to your reputation
ACA
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue when opening word file msadiqrajani Word 2 05-27-2011 08:11 PM
MS Word - There was an error opening the file cookiegal Word 7 04-04-2011 12:37 AM
Opening zip file attachments in MS Outlook shankar Outlook 0 12-07-2010 09:15 PM
problem opening ms word 2007 file shanchita rahman Word 0 11-17-2010 08:43 AM
Opening MSO-2000 file in MSO-2003 w77 Word 0 04-21-2009 03:30 AM


All times are GMT -7. The time now is 10:11 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft