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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating code to bring up a dialogue box when save button is hit

Status
Not open for further replies.

KenArmstrong

IS-IT--Management
Apr 9, 2003
4
AU
Ok - i'm pretty green on VBA coding - have done a little but have no idea where to start on this idea.

The idea
Background - we have a strict naming & filing structure for our documents. Currently you need to refer to a cheat sheet to work out name and where to save a document. When your in a hurry or have ADD like the boss you don't take the time and documents end up all over the place.

WHat i want to happen is when user clicks save button, up comes a dialogue box that guides the process of naming and saving in correct location.

It would be a series of checkboxes for the various levels in the naming convention

ie "A" for acquisition "B01" for Authorities "B02" for Consultants - then one of those is selected it brings up the next layer of choice IE "01_town_planning" etc etc

I'm happy to hard code the structure in - it won't change that often.

Then when user has made selection it is transferred into the path for the save

There'll be a few other issues but i want to get started and see if i can iron out bugs.

Suggestions on training/ tutuorials accepted

Thanks
Ken
 
Hi Ken,

In Word, you can override any built-in command by creating a macro with the appropriate name - in this case [blue]FileSave[/blue] (and you might also want to add [blue]FileSaveAs[/blue] as well). In this routine you can do as you wish and it will run instead of the native Word function.

Sounds like you want a UserForm to get all your questions answered to generate the FileName, and then save under that name. There is no requirement for the standard Word dailog to be presented to the user at all.

I'm not sure how much of this you need help with - would you care to post any specific questions (which might be a basic "what is a userform") so we can give appropriate answers.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Thanks tony - yes that is a good start and yes i want a form to pop up that the user can select from the choices, with the only variable being part of the filename - i'm a bit anal on file naming - i was i a large office where if docs weren't named correctly they got lost!

So yes how do i code a "userform"

Thanks again - and if the questions are too basic and there is reading i can do - just direct to the source
 
Hi Ken,

I'm not sure it's the easiest place to start but to create a userform ..

Press Alt+F11 from Word to bring up the VBE (if even this is alien to you, e-mail me (my handle here at VBAExpress dot com) and I'll send you a document all about how to work in the VBE)
Press Ctrl+r to bring up the Project Explorer if not visible
In the Project Explorer right click on the entry for your document and choose Insert > Userform

You will get a blank form and should see the toolbox (if not, select View > Toolbox from the menu)

Add the controls you want from the toolbox - you'll have to experiment to see how they can be moved and resized with the mouse or you can do it all via the properties window (Press F4 if it's not visible).

When you've designed the form you'll need to add code to it (double click on the form or press F7 or use one of the other ways to see the code). Use the two dropdowns at the top of the code window to select the event routines you want to code in - BeforeUpdate on individual controls is a good place to put validation - use the Click event of a command button to do your save stuff.

When you've got a userform - right click in the project explorer again and Insert > Module then enter:

Sub FileSave()
UserForm1.Show
End Sub

Userform1 is a default name - if you've changed it you'll need to use whatever name you've given it instead.

Hope that's enough to get you started.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Just thought I would throw in a couple considerations you will need to make...I created a document with extensive naming logic and ended up having to scrap most of it for various reasons...

1) Where will the document be stored? A FileNET type of environment does not work well with the FileSave, or FileSaveAs, events...This is from the Web view tool...

2) What do you want to do with a document that has already been named, by your code? Do you want to have them go through the naming logic again, and possibly create a new name? If on a shared drive, this can start to get messy. If you do not want to repeat the naming logic, then you need to add some logic to the Document Open event to detect if this document has already been named through your logic and set a flag to not do it again.

Just a couple things to think about...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top