Solved

msoFileDialogSaveAs options

Posted on 2008-10-16
11
477 Views
Last Modified: 2012-05-05
Looking to combine two things.  First, I have code to determine the "CurrentFolder" that the ActiveDocument is from.  Second, I know how to call the msoFileDialogSaveAs dialog and create have an InitialFileName placed in the Save As field.  However, I want the folder to be the Current Folder, not the MyDocuments folder.  That is, I want the automated setting to be when the Save As dialog appears to be twofold: first a "recommended" file name (InitialFileName), and a "recommend" folder location (Current Folder), so that the user has essential the option of just selecting save with no further manipulation of the Save As dialog.
0
Comment
Question by:HardyDesertDuo
  • 6
  • 5
11 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
An open document has a Path property, so
strCurrentFolder = ActiveDocument.Path would give you that.

I usually use the Word SaveAs dialogue. This has a Name property:

    Dim dlg As Dialog
    Set dlg = Dialogs(wdDialogFileSaveAs)
    dlg.Name = ActiveDocument.FullName
    dlg.Show
0
 

Author Comment

by:HardyDesertDuo
Comment Utility
Doesn't work.  I guess I want to change the "default" folder to be the folder of the ActiveDocument.Path so that when I select "Save As" on the command bar, the dialog is down the directory tree to the ActiveDocument.Path
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
It works with the Word dialogue. I tested it again before posting.

I recall that Chdir (change default directory) also works if the path is not supplied in the Name string.
Note that new documents (Document1, etc) will not have a path om th FullName property.

If you are using the Office dialogue, can you post your code, please?
0
 

Author Comment

by:HardyDesertDuo
Comment Utility
Okay.  Sorry for the confusion.  I'm working with a new document (Document1, etc) from a template.  I'm trying to "force" the Save As dialog to "open" to the same folder as the document template from which the Document1 was "created."  I've been fooling around with iterations of Chdir and ActiveDocument.AttachedTempate.Path which "works' inasmuchas I can created a string of the path I want Document1 to go in, but I cannot seems to get that path associated with the Save As dialog the first time I try to save Document1.  I also want to "suggest" a name for Document1 in the Save As dialog.  So, the sequence of events is as follows: Start a new document from a Template, information is entered into a userform that opens when a new document is started, upon selecting the command button "Create Document" on the userform, the FormFields in the document are populated based on userform entry.  Now, when the user selects "Save As" (in Word command bar), I want the the Save As dialog to default to the directory from which the original template came and "suggest" the name of the file to be a string based on userform information, not Document1 (I know how to create that string...just don't know how to make it the Name for Save As dialog).  Would ChangeFileOpenDirectory help?  OBTW: I'll use Word dialog, not a problem there.
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
Does this help?
Sub MyFileSaveAs()

    Dim dlg As Dialog

    Set dlg = Dialogs(wdDialogFileSaveAs)

    dlg.Name = ActiveDocument.AttachedTemplate.path & "\" & "SuggestedName.doc"

    dlg.Show

End Sub

Open in new window

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:HardyDesertDuo
Comment Utility
How do I associate (call) the MyFileSaveAs procedure with the "Save As" command on the Command Tool Bar?
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 125 total points
Comment Utility
Use Tools/Customize to en the Customize window.

If necessary, you can create a new toolbar with the Toolbars tab. You can also make sure that the target toolbar is visible here.

On the Commands tab, select Macros in Categories, then find your macro in the right-hand box and drag it to the toolbar of your choice. While it is selected, now or later, you can edit it by using the Modify Selection button.
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
Oops. "en" should be "open"
0
 

Author Closing Comment

by:HardyDesertDuo
Comment Utility
I successfully created a new toolbar command button called "Save Document" that is associated with the MyFileSaveAs macro.  That's probably what I'm gonna have to go with and not use the built-in Save As command.
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
I didn't take on board the fact that you wanted to intercept the FileSaveAs command.

A macro with the same name as a Word command will run in preference to the Command itself, so you simply need to change the macro name to FileSaveAs. It will then run if the user tries to save to use File/SaveAs menu item.
0
 

Author Comment

by:HardyDesertDuo
Comment Utility
Awesome!  Sorry for the confusion.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now