Word 2003 macro to open to a folder

blackranger
blackranger used Ask the Experts™
on
I have folders set up for word docs I use regularly such as Forms, Checklists, Procedures etc . These folders contain many forms, many checklists, many procedures etc. I have added a custom menu item which contains Forms, Checlists, Procedures etc.

 What I want to do is when I click on the Forms Item in the custom menu I wish the file open dialog box to open in the forms folder listing the existing forms or if I click on the Procedures Item in the custom menu then  the file open dialog box to open in the Procedures folder listing the existing Procedures available

Any advice is appreciated Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
GrahamSkanRetired
Top Expert 2012

Commented:
You could try a macro like this
Sub OpenMyFolder(strFolder As String)
Dim dlg As Dialog
 
Set dlg = Dialogs(wdDialogFileOpen)
 
'open folder with a legal file name (not necessarily present)
dlg.name = strFolder & "\" & "any.doc"
dlg.Display 1
'open previously established folder with a blank name
dlg.name = strFolder & "\" & "*.doc"
If dlg.Show = -1 Then
    Documents.Open dlg.name
End If
End Sub

Open in new window

Author

Commented:
I have been using the following macro to open the checklists folder when I click on the checklist menu item. It works fine the first time, after that it reverts to the 'my documents' folder.

To clarify, the first time you click the Checklists menu item the openfile dialog opens in the Checklists folder. Good this is what I want to happen every time.

If you close the dialog box and click the Checklists item in the menu again the fileopen dialog opens in the 'my documents' folder. Bad I want it to open in the Checklists folder.

What am I doing wrong

Thanks
Sub OpenChecklists()
' Open checklist menu option
'
   
   ChangeFileOpenDirectory "Z:\PROGRAM\AATA Docs\Checklists\"
   Dialogs(wdDialogFileOpen).Show

Open in new window

GrahamSkanRetired
Top Expert 2012

Commented:
Your way of changing the default open directory should work as well as my unofficial way.

I have tried your better technique, and it seems to work every time


Sub OpenMyFolder(strFolder As String)
Dim dlg As Dialog
 
Set dlg = Dialogs(wdDialogFileOpen)
 
'dlg.name = strFolder & "\" & "any.doc"
'dlg.Display 1
ChangeFileOpenDirectory strFolder
dlg.name = strFolder & "\" & "*.doc"
If dlg.Show = -1 Then
    Documents.Open dlg.name
End If
End Sub

Open in new window

Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Author

Commented:
Hi GrahamSkan,
Thank you for your interest,
Could the problem be that I working on a large network and the administrators control the default file locations in the options settings and that Word reverts to these settings?

if this is the  case Is there any way around this programatically as I know the network administrator will not allow default settings to be changed.

Thanks
GrahamSkanRetired
Top Expert 2012

Commented:
I am still a bit puzzled as to exactly what happens.
Does the code work once, and not a second time? What happens on a third attempt?

Also what do you call the first time - i.e. you run it once. It fails until...
I have solved this problem by finding an ealier question and solution. see the code snippet, with a bit of changing it now works all the time.

Thank You
dirpath = Cpath1 + MyValue
        Set fd = Application.FileDialog(msoFileDialogOpen)
        fd.InitialFileName = dirpath + "\*.*"
       If fd.Show Then
            Application.Documents.Open fd.SelectedItems(1)
            fd.Execute
        End If
        Set fd = Nothing
        Exit Sub

Open in new window

GrahamSkanRetired
Top Expert 2012

Commented:
Obviously I have failed to understand the problem

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial