Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macro to Open Window with just *.doc, & *.docx files 1

Status
Not open for further replies.
Jun 5, 2002
417
0
0
AU
Hi,

I have this macro in Excel to just display *.csv files in the Open Window:

Sub CSVOpen()
'
' CSVOpen Macro to Open Window for *.csv files in dir "Super"
'
Dim myFileName As Variant
Dim Wkbk As Workbook

ChDir "C:\Users\Peter\Documents\Super"
myFileName = Application.GetOpenFilename("Text Files (*.csv), *.csv", Title:="Please Select a File")

If myFileName = False Then
ChDir "C:\Users\Peter\Documents"
Exit Sub 'user hits Cancel
End If

Workbooks.OpenText Filename:=myFileName, _
DataType:=xlDelimited, Comma:=True 'Open selected file

ChDir "C:\Users\Peter\Documents" 'Reset CurDir to "Documents" for next use.

End Sub

I would like to have a similar macro in Word with just *.doc and *.docx files, which is not possible via the Ctrl+O window. I tend to have *.PDF files in the relevant folders which I don't want to show, but which Word insists on showing.

Any suggestions gratefully appreciated on how to do this for Word.

Peter Moran


 
Hi Peter,

this should do the trick:
Code:
Sub OpenDocOnly()

Dim dlgOpen As FileDialog, Res As Integer

Set dlgOpen = Application.FileDialog(msoFileDialogOpen)

dlgOpen.Filters.Clear
dlgOpen.Filters.Add "Doc* Files", "*.doc*"
dlgOpen.Title = "Please select a file"
Res = dlgOpen.Show

If Not Res = 0 Then
    'Do your magic
End If

End Sub

Cheers,
MakeItSo

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Hi MakeItSo,

Thanks for your quick reply.

Will check it out and let you know how I go.

Cheers,Peter Moran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top