• Macro for opening folder (Word 2000 SR3)

    Author
    Topic
    #397155

    Hi All

    I am looking to create a macro that opens a folder to allow the user to choose the file they want from within it. I know this must be fairly easy but am having one of those days and can only get it to work if I choose a file from within the folder. Any help would be much appreciated

    Viewing 1 reply thread
    Author
    Replies
    • #749843

      The instruction to change to another folder is ChangeFileOpenDirectory “C:Path” (substitute the appropriate path). You can then present the Open File dialog with Dialogs(wdDialogFileOpen).Show.

      • #749954

        Thanks that worked a treat. Is there a similar command for File New. The scenario I am trying to create is a menu for the templates in the firm by department and I dont want anyone opening the templates I need it to be as if they had gone into File New and selected it. So basically they will click on a menu with a number of departments listed and when they click on the dept I want them to access the Files but as templates so they launch as a document and dont open as the selected template.

        I hope that makes sense. Any help would be much appreciated

        • #749970

          You should set the User Templates and/or Workgroup Templates paths for this; the File | New dialog is very different from the File | Open dialog: you can’t navigate to other folders, only to the various tabs in the dialog. And unless you uninstall the Microsoft templates, they will always be displayed.

          To get/set the User Templates path in code, use Options.DefaultFilePath(wdUserTemplatesPath), and to get/set the Workgroup Templates path, use (you guessed it) Options.DefaultFilePath(wdWorkgroupTemplatesPath).

          • #750227

            Again this works perfectly so thanks – only problem is it is bringing in tabs for Legal Pleadings, Letters and Faxes etc that I don’t want – I only want to show the templates in the folder I have set. Is there a way to do this.

            thanks for your help

            • #750233

              I think that the only way to get rid of these tabs is to uninstall the templates that come with Word.
              Open the Add/Remove Programs control panel.
              Select Microsoft Office or Microsoft Word, depending on how you installed Word.
              Indicate that you want to modify the existing installation.
              Clear the check box for the templates.

              This will have to be done for each PC…

            • #768397

              Is there any way, other than setting the file new path, to have the documents displayed opened as templates – ie as docX rather than the file name as read only. I need the users to be able to choose from the list but for it to open as a template if possible
              Thanks in advance

            • #768437

              It is possible to use VBA code to display a list of files, then create a new document based on the document selected by the user. The user would have to use a custom toolbar button or menu item instead of File | New…
              I don’t know how familiar you are with writing VBA code for Word.

            • #768438

              It is possible to use VBA code to display a list of files, then create a new document based on the document selected by the user. The user would have to use a custom toolbar button or menu item instead of File | New…
              I don’t know how familiar you are with writing VBA code for Word.

            • #768926

              Hi Boyley:
              I’m curious as to what you’re trying to accomplish. Normally, you would simply have a list of templates & users would open a document based on them. I can’t think of a reason why you would want users to open a template, rather than a document based on that template.
              Cheers,

            • #769336

              The scenario is I have 7 departments – I am creating 7 Normal.dots, one for each department – I want to have a menu on the toolbar that when accessed has 3 options

              1. the department templates for the department they are in – and only display that department
              2. other department templates – should they need them
              3. general templates – fax, memo etc

              In each case I want them to be opened as templates not documents. I am sure there is an easier way to do it but this is they way I have in my head and am playing around with it to get it to work.

              Hope this makes sense.

            • #769510

              > In each case I want them to be opened as templates not documents.

              This statement is confusing (at least to me). It’s better to say whether you want File>New behavior, which generates a new document and doesn’t open the chosen template, or File>Open behavior, which opens the file. Based on the above, I think you want the File>New behavior. Hopefully the macro will help.

            • #769511

              > In each case I want them to be opened as templates not documents.

              This statement is confusing (at least to me). It’s better to say whether you want File>New behavior, which generates a new document and doesn’t open the chosen template, or File>Open behavior, which opens the file. Based on the above, I think you want the File>New behavior. Hopefully the macro will help.

            • #769620

              Hi Boyley:
              I really think that what you need is to create a new document from the templates, not open the templates. You can place styles, Autotext entries, shortcut keys, macros, boilerplate text & toolbars in your various templates. These will all be available when you create a new document based on one of those templates.

              You can create a toolbar that lists all the department templates in a dropdown menu. Another toolbar can list other department templates. You can create such “flyout” menus by using Tools/Customize…/Commands tab & look for New Menu at the bottom. You can drag this to a toolbar or to a new menu on the toolbar.

              Then you can keep all the templates in your Workgroup Templates Folder. If you allow each Department to open the templates, then anyone can modify your template…destroy your macros, change the styles, etc. Then the next person won’t be able to use it.

              I’ve attached an example of a template with such a toolbar, but, of course, it doesn’t point to any templates.

            • #769621

              Hi Boyley:
              I really think that what you need is to create a new document from the templates, not open the templates. You can place styles, Autotext entries, shortcut keys, macros, boilerplate text & toolbars in your various templates. These will all be available when you create a new document based on one of those templates.

              You can create a toolbar that lists all the department templates in a dropdown menu. Another toolbar can list other department templates. You can create such “flyout” menus by using Tools/Customize…/Commands tab & look for New Menu at the bottom. You can drag this to a toolbar or to a new menu on the toolbar.

              Then you can keep all the templates in your Workgroup Templates Folder. If you allow each Department to open the templates, then anyone can modify your template…destroy your macros, change the styles, etc. Then the next person won’t be able to use it.

              I’ve attached an example of a template with such a toolbar, but, of course, it doesn’t point to any templates.

            • #769337

              The scenario is I have 7 departments – I am creating 7 Normal.dots, one for each department – I want to have a menu on the toolbar that when accessed has 3 options

              1. the department templates for the department they are in – and only display that department
              2. other department templates – should they need them
              3. general templates – fax, memo etc

              In each case I want them to be opened as templates not documents. I am sure there is an easier way to do it but this is they way I have in my head and am playing around with it to get it to work.

              Hope this makes sense.

            • #774360

              My language here was the problem – I dont want them to open as a template, i do need them to open as a document. Each department will have thier own normal.dot from which they will launch thier department styles. In Normal.dot but I want to create a menu entry such as “Corporate Styles” that when you click on will open up a dialog box where the styles can be chosen and opened as if you had gone into file new – in this box there would be no other templates available other than those required for the corporate dept – these would be in tabs again (as the styles are stored in folders) as if they were in file new. the structure is

              Corporate Styles (folder)
              Styles 1 (subfolder)
              Styles 2 (subfolder)
              Styles 3 (subfolder)
              Styles 4 (subfolder)
              Styles 5 (subfolder)
              Styles 6 (subfolder)

              The folders are set up on the network with each department having their own folder with subfolders, Litigation styles, Property styles etc.

              Some departments need access to other department styles occasionally so in the same menu there might be Litigation styles where when clicked on the same scenario as the first would occur – a box with only litigation styles in it. I cant list them individually as some departments have hundreds of styles. This might not be able to be done or be too difficult for me to try but it is ideally the way I would like users to be able to work

            • #774380

              Hi Boyley:
              I’m not sure that I know how to do what you want. It appears that you are copying styles into a document when you list:
              Corporate Styles (folder)
              Styles 1 (subfolder)
              Styles 2 (subfolder)
              Styles 3 (subfolder)
              Styles 4 (subfolder)
              Styles 5 (subfolder)
              Styles 6 (subfolder)

              However, styles are found in templates & documents. The Styles 1, etc. that you’ve listed would either have to be a macro to create &/or copy those styles from another template. If those “style” templates exist, all you have to do is create a document based on them & the styles will be available.

              I suppose that a macro which opened the Format/Theme…/Style Gallery dialog box, picked a particular template, & then copied the styles would do what you’re asking, but I’m afraid I’m not a VBA expert. Still, I don’t see any advantage to that method over creating a new document based on the correct template. You can do that with the toolbar dropdown menu that I showed you in post 332176.

              The advantage to a new document based on a template is that you can have special autotext that would only apply to litigation, property, etc. in a given template.
              Hope this helps,

            • #776173

              I do want to create a document based on the correct template. the templates will be in the folders called style 1 etc.

              In MSWord if you go into File New (Where word has had no customisation) you will see the tabs General, Letters and Memos, Reports etc where you choose the template from that you want to run. What I want is when I click on the option for Corporate styles – it to display the tabs style 1etc (as per the folders) with the templates listed that you will choose and a document based on that template will be created. Also in the same normal.dot I want the user to be able to choose the option for “banking styles” and the dialog box to reflect the subfolders within this. It would mean that each user would get quick access to each departments styles.

              I hope this makes a little more sense now

            • #776551

              Hi Boyley:
              I think understand what you’re trying to do. It sounds like you want to develop your own userform with tabs that would act the way File/New… does. I don’t know how to do that. I’m not saying that it can’t be done, but I don’t know how. Personally, I like to use a dropdown toobar to select new documents based on templates. Depending on how you name the toolbar, it’s dropdown menus, & templates, it lets users use keyboard combinations for creating the most common documents, something I find to be a timesaver.
              Cheers,

            • #779195

              thanks Phil

              you have hit the nail on the head with what I want to do. I agree with you re the drop down menu – my problem is that some of the departments have hundreds of items they would want in the list so it would be incredibly time consuming and I thought the file/new type box would be best in this instance. I am using the menu item for firm wide templates such as our Fax, Memo and letter and find it works beautifully.

              I will keep trying and hopefuly will get something sorted. Thanks again for your help

            • #779222

              Hi Boyley,

              Maybe you can use something along these lines:
              1. Place the templates in separate subdirs for each department (Dept1; Dept2; etc.)
              2. Write Sub DeptTemplates
              3a. Place a button on the Toolbar that calls DeptTemplates (if you want to preserve the standard FileNew command)
              or
              3b. Rename Sub DeptTemplates to FileNew (if you want to “hijack” the standard FileNew command)

              Public Sub DeptTemplates
              Dim strOld As String
              Dim strDept As String
              strDept = InputBox(“Department name?”)
              strOld = Options.DefaultFilePath(wdWorkgroupTemplatesPath)
              Options.DefaultFilePath(wdWorkgroupTemplatesPath) = “” & strDept
              Dialogs(wdDialogFileNew).Show
              Options.DefaultFilePath(wdWorkgroupTemplatesPath) = strOld
              End Sub

              Ofcourse you can use a dialog panel with a drop-down list for the departments. Otherwise you have to put some code in this Sub to check wether the user input is in fact an existing department. If not you can put the Inputbox on the screen again, or revert to a default path.
              The lines with strOld in them can be omitted, but I think it’s good practice to put things back to the state/value it had before my code changed it.

              Hope this helps
              JanB

            • #779223

              Hi Boyley,

              Maybe you can use something along these lines:
              1. Place the templates in separate subdirs for each department (Dept1; Dept2; etc.)
              2. Write Sub DeptTemplates
              3a. Place a button on the Toolbar that calls DeptTemplates (if you want to preserve the standard FileNew command)
              or
              3b. Rename Sub DeptTemplates to FileNew (if you want to “hijack” the standard FileNew command)

              Public Sub DeptTemplates
              Dim strOld As String
              Dim strDept As String
              strDept = InputBox(“Department name?”)
              strOld = Options.DefaultFilePath(wdWorkgroupTemplatesPath)
              Options.DefaultFilePath(wdWorkgroupTemplatesPath) = “” & strDept
              Dialogs(wdDialogFileNew).Show
              Options.DefaultFilePath(wdWorkgroupTemplatesPath) = strOld
              End Sub

              Ofcourse you can use a dialog panel with a drop-down list for the departments. Otherwise you have to put some code in this Sub to check wether the user input is in fact an existing department. If not you can put the Inputbox on the screen again, or revert to a default path.
              The lines with strOld in them can be omitted, but I think it’s good practice to put things back to the state/value it had before my code changed it.

              Hope this helps
              JanB

            • #779196

              thanks Phil

              you have hit the nail on the head with what I want to do. I agree with you re the drop down menu – my problem is that some of the departments have hundreds of items they would want in the list so it would be incredibly time consuming and I thought the file/new type box would be best in this instance. I am using the menu item for firm wide templates such as our Fax, Memo and letter and find it works beautifully.

              I will keep trying and hopefuly will get something sorted. Thanks again for your help

            • #776552

              Hi Boyley:
              I think understand what you’re trying to do. It sounds like you want to develop your own userform with tabs that would act the way File/New… does. I don’t know how to do that. I’m not saying that it can’t be done, but I don’t know how. Personally, I like to use a dropdown toobar to select new documents based on templates. Depending on how you name the toolbar, it’s dropdown menus, & templates, it lets users use keyboard combinations for creating the most common documents, something I find to be a timesaver.
              Cheers,

            • #776174

              I do want to create a document based on the correct template. the templates will be in the folders called style 1 etc.

              In MSWord if you go into File New (Where word has had no customisation) you will see the tabs General, Letters and Memos, Reports etc where you choose the template from that you want to run. What I want is when I click on the option for Corporate styles – it to display the tabs style 1etc (as per the folders) with the templates listed that you will choose and a document based on that template will be created. Also in the same normal.dot I want the user to be able to choose the option for “banking styles” and the dialog box to reflect the subfolders within this. It would mean that each user would get quick access to each departments styles.

              I hope this makes a little more sense now

            • #774381

              Hi Boyley:
              I’m not sure that I know how to do what you want. It appears that you are copying styles into a document when you list:
              Corporate Styles (folder)
              Styles 1 (subfolder)
              Styles 2 (subfolder)
              Styles 3 (subfolder)
              Styles 4 (subfolder)
              Styles 5 (subfolder)
              Styles 6 (subfolder)

              However, styles are found in templates & documents. The Styles 1, etc. that you’ve listed would either have to be a macro to create &/or copy those styles from another template. If those “style” templates exist, all you have to do is create a document based on them & the styles will be available.

              I suppose that a macro which opened the Format/Theme…/Style Gallery dialog box, picked a particular template, & then copied the styles would do what you’re asking, but I’m afraid I’m not a VBA expert. Still, I don’t see any advantage to that method over creating a new document based on the correct template. You can do that with the toolbar dropdown menu that I showed you in post 332176.

              The advantage to a new document based on a template is that you can have special autotext that would only apply to litigation, property, etc. in a given template.
              Hope this helps,

            • #774361

              My language here was the problem – I dont want them to open as a template, i do need them to open as a document. Each department will have thier own normal.dot from which they will launch thier department styles. In Normal.dot but I want to create a menu entry such as “Corporate Styles” that when you click on will open up a dialog box where the styles can be chosen and opened as if you had gone into file new – in this box there would be no other templates available other than those required for the corporate dept – these would be in tabs again (as the styles are stored in folders) as if they were in file new. the structure is

              Corporate Styles (folder)
              Styles 1 (subfolder)
              Styles 2 (subfolder)
              Styles 3 (subfolder)
              Styles 4 (subfolder)
              Styles 5 (subfolder)
              Styles 6 (subfolder)

              The folders are set up on the network with each department having their own folder with subfolders, Litigation styles, Property styles etc.

              Some departments need access to other department styles occasionally so in the same menu there might be Litigation styles where when clicked on the same scenario as the first would occur – a box with only litigation styles in it. I cant list them individually as some departments have hundreds of styles. This might not be able to be done or be too difficult for me to try but it is ideally the way I would like users to be able to work

            • #768927

              Hi Boyley:
              I’m curious as to what you’re trying to accomplish. Normally, you would simply have a list of templates & users would open a document based on them. I can’t think of a reason why you would want users to open a template, rather than a document based on that template.
              Cheers,

            • #769007

              Following Hans’ suggestion, try something along these lines:

              Sub FileNewUsingFileOpenDlg()
              Dim strStartPath As String, docNew As Document
              strStartPath = "serversharefolder"      'Change this to fit your servername pathfolder
              ChangeFileOpenDirectory strStartPath
              With Dialogs(wdDialogFileOpen)
                  If .Display = True Then
                      Set docNew = Documents.Add(Template:= _
                          Options.DefaultFilePath(wdCurrentFolderPath) & _
                          Application.PathSeparator & Replace(.Name, """", ""), _
                          Visible:=True)
                      docNew.Activate
                      Set docNew = Nothing
                  End If
              End With
              End Sub

              What it does is show the File Open dialog and, if the user chooses Open, feeds the path and file name to the function that creates a new document from what the user chose. By default, Word will shows both DOC and DOT files (and HTM, RTF, etc.), but it should be possible to change this by passing a .Name parameter to the dialog.

            • #769008

              Following Hans’ suggestion, try something along these lines:

              Sub FileNewUsingFileOpenDlg()
              Dim strStartPath As String, docNew As Document
              strStartPath = "serversharefolder"      'Change this to fit your servername pathfolder
              ChangeFileOpenDirectory strStartPath
              With Dialogs(wdDialogFileOpen)
                  If .Display = True Then
                      Set docNew = Documents.Add(Template:= _
                          Options.DefaultFilePath(wdCurrentFolderPath) & _
                          Application.PathSeparator & Replace(.Name, """", ""), _
                          Visible:=True)
                      docNew.Activate
                      Set docNew = Nothing
                  End If
              End With
              End Sub

              What it does is show the File Open dialog and, if the user chooses Open, feeds the path and file name to the function that creates a new document from what the user chose. By default, Word will shows both DOC and DOT files (and HTM, RTF, etc.), but it should be possible to change this by passing a .Name parameter to the dialog.

            • #768398

              Is there any way, other than setting the file new path, to have the documents displayed opened as templates – ie as docX rather than the file name as read only. I need the users to be able to choose from the list but for it to open as a template if possible
              Thanks in advance

            • #750234

              I think that the only way to get rid of these tabs is to uninstall the templates that come with Word.
              Open the Add/Remove Programs control panel.
              Select Microsoft Office or Microsoft Word, depending on how you installed Word.
              Indicate that you want to modify the existing installation.
              Clear the check box for the templates.

              This will have to be done for each PC…

          • #750228

            Again this works perfectly so thanks – only problem is it is bringing in tabs for Legal Pleadings, Letters and Faxes etc that I don’t want – I only want to show the templates in the folder I have set. Is there a way to do this.

            thanks for your help

        • #749971

          You should set the User Templates and/or Workgroup Templates paths for this; the File | New dialog is very different from the File | Open dialog: you can’t navigate to other folders, only to the various tabs in the dialog. And unless you uninstall the Microsoft templates, they will always be displayed.

          To get/set the User Templates path in code, use Options.DefaultFilePath(wdUserTemplatesPath), and to get/set the Workgroup Templates path, use (you guessed it) Options.DefaultFilePath(wdWorkgroupTemplatesPath).

      • #749955

        Thanks that worked a treat. Is there a similar command for File New. The scenario I am trying to create is a menu for the templates in the firm by department and I dont want anyone opening the templates I need it to be as if they had gone into File New and selected it. So basically they will click on a menu with a number of departments listed and when they click on the dept I want them to access the Files but as templates so they launch as a document and dont open as the selected template.

        I hope that makes sense. Any help would be much appreciated

    • #749844

      The instruction to change to another folder is ChangeFileOpenDirectory “C:Path” (substitute the appropriate path). You can then present the Open File dialog with Dialogs(wdDialogFileOpen).Show.

    Viewing 1 reply thread
    Reply To: Macro for opening folder (Word 2000 SR3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: