Set curdir from where template was opened

I have an app where there is a templete that resides in a directory, 
under this directory is a data storage folder, the location of the 
template can change.  Part of the code builds the require directory 
structure below the template location.

Is there a way to set the curdir to where the workbook was opened from 
ie: where template sits?  I am interupting the save process so I can set 
the name of the file depending on values within a worksheet, it needs to 
default to the "place where template is"\datastore\"Name I define".xls

TIA

W


Code below FYI:

Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

     'error trap
     On Error GoTo Etrap

     Dim MyCell, mySavePath, mySaveName

     MyCell = Range("Summary!B6")
     mySavePath = CurDir & "\datastore\"
     mySaveName = mySavePath & MyCell
     'MsgBox (CurDir & "\datastore\" & MyCell)

     ' confirm the datastore directory exists, if not create it.
     Dim FSO
     Set FSO = CreateObject("Scripting.FileSystemObject")
     If FSO.folderexists(mySavePath) Then
     Else
     FSO.createfolder (mySavePath)
     End If

     'check value of activecell
     If MyCell = "0" Then
     MsgBox "Please check you have a candidate name", vbInformation
     Exit Sub
     End If

     'ask user to save
     'If MsgBox("Save new workbook as " & CurDir & "\datastore\" & 
MyCell & ".xls?", vbYesNo) = vbNo Then
     'Exit Sub
     'End If

     'save activeworkbook as new workbook
     ActiveWorkbook.SaveAs Filename:=mySaveName & ".xls", 
FileFormat:=xlNormal


Etrap:

     Beep
Exit Sub
0
6/7/2004 4:01:59 AM
excel.misc 78881 articles. 5 followers. Follow

1 Replies
671 Views

Similar Articles

[PageSpeed] 46

Once the user creates a new workbook based on a template, then any connection to
that template's folder is lost.

Any way you can create a macro that allows the user to pick the template, but
you can monitor from where they opened the template?

kind of:

Option Explicit
Sub openTemplate()

    Dim myPath As String
    Dim myFileName As Variant
    
    myFileName = Application.GetOpenFilename _
                   (filefilter:="Template files, *.xlt", _
                    Title:="Create a New Workbook Based on This Template")
    
    If myFileName = False Then
        Exit Sub 'user hit cancel
    Else
        Workbooks.Add template:=myFileName
    End If
    
    myPath = Mid(myFileName, 1, InStrRev97(myFileName, "\") - 1)
    
    MsgBox myPath
    
End Sub

Function InStrRev97(mystr As Variant, mydelim As String) As Long

    Dim i As Long
    InStrRev97 = 0
    For i = Len(mystr) To 1 Step -1
        If Mid(mystr, i, 1) = mydelim Then
            InStrRev97 = i
            Exit Function
        End If
    Next i
End Function

====
If you're using xl2k or higher, you can replace instrrev97 with InstrRev.  And
dump the function itself.  (InstrRev was added in xl2k.)




William Hamilton wrote:
> 
> I have an app where there is a templete that resides in a directory,
> under this directory is a data storage folder, the location of the
> template can change.  Part of the code builds the require directory
> structure below the template location.
> 
> Is there a way to set the curdir to where the workbook was opened from
> ie: where template sits?  I am interupting the save process so I can set
> the name of the file depending on values within a worksheet, it needs to
> default to the "place where template is"\datastore\"Name I define".xls
> 
> TIA
> 
> W
> 
> Code below FYI:
> 
> Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> 
>      'error trap
>      On Error GoTo Etrap
> 
>      Dim MyCell, mySavePath, mySaveName
> 
>      MyCell = Range("Summary!B6")
>      mySavePath = CurDir & "\datastore\"
>      mySaveName = mySavePath & MyCell
>      'MsgBox (CurDir & "\datastore\" & MyCell)
> 
>      ' confirm the datastore directory exists, if not create it.
>      Dim FSO
>      Set FSO = CreateObject("Scripting.FileSystemObject")
>      If FSO.folderexists(mySavePath) Then
>      Else
>      FSO.createfolder (mySavePath)
>      End If
> 
>      'check value of activecell
>      If MyCell = "0" Then
>      MsgBox "Please check you have a candidate name", vbInformation
>      Exit Sub
>      End If
> 
>      'ask user to save
>      'If MsgBox("Save new workbook as " & CurDir & "\datastore\" &
> MyCell & ".xls?", vbYesNo) = vbNo Then
>      'Exit Sub
>      'End If
> 
>      'save activeworkbook as new workbook
>      ActiveWorkbook.SaveAs Filename:=mySaveName & ".xls",
> FileFormat:=xlNormal
> 
> Etrap:
> 
>      Beep
> Exit Sub

-- 

Dave Peterson
ec35720@msn.com
0
ec35720 (10082)
6/7/2004 10:45:30 PM
Reply:

Similar Artilces:

OWA Set Rule problem
I have successfully install the Exchange 2003 with SP1 in the Windows Server 2003. Anything alright exclude the rules function in OWA. I try to set the rules from any then "move to" or "copy to" specify folder are no problem, but "forward to" other email address, its don't work. I try to input the email address in the contact and then select from the contact, but the result also don't work. The rules can save and I can receive the incoming email in the Exchange 2003/Outlook or OWA, but it don't forward to my specify email address. I try to...

Javascript Error opening threads
In Windows XP General Discussions, when I click on a thread to expand it, it says 'loading' but there is a 'javascript 0' error message on the left side of the status bar. When I attempt to refresh the page, it says 'service temporarily unavailable.' Anyone else have this issue? What's the fix? The issue is that the newsserver for the web-interface is horked /again/. The fix is to access this and other MS newsgroups in your newsreader (e.g., Outlook Express). Setting up Outlook Express to access Microsoft newsgroups http://www.michaelstevenstec...

How do I set up an argument which asks for multiple criteria
I am trying to use an argument that asks for one of three criteria (2345P, 8319T, or 7026J) in cell C108, and if it finds it, enters the amount of yet another cell, G108 into cell K108, and if not enters 0 into cell K108. It seems there are too many arguments for the "if" argument, and I can't seem to get the "lookup" argument to work either. Is there another argument I should be working with? Thanks -- Diver Try: =IF(OR(C108="8319T",C108="2345P",C108="7026J"),G108,0) "bj" wrote: > try in K108 > =if(or(c108=&qu...

setting up new outlook mail account
i can not set up a new account on my outlook, i keep saying establish network connection with a correct sign but searching for my mail account shows X can you please advise Are you trying to setup a POP3 mail account or an Exchange account? Also, what version of Outlook are you using? "rashid" <rashid@discussions.microsoft.com> wrote in message news:C59D04C0-C1C9-4BD1-AE00-2009D25B221D@microsoft.com... > i can not set up a new account on my outlook, i keep saying establish > network > connection with a correct sign but searching for my mail account shows X > ...

How do I set the 'Set Synchronizing Client' field
We have a number of outlook clients using CRM that have the 'Set Synchronizing Client' select box greyed out. We need to tick them so that they are able to synchronize tasks etc. Can any one help me find out why these are greyed out and then set them so that they can synchronize thanks In my experience, that checkbox is always greyed out for the first install that is performed for a user. The only time that checkbox becomes active is if a second copy of CRM is installed for a user who already has CRM installed on another PC.... Normally the box is checked and grey. If that is...

How can I open outlook in a different inbox, i.e.hotmail ?
I am using Microsoft Outlook 2002 i Windows XP and opens in its own inbox. Is it possible to set it to open in the Hotmail inbox where my mail is found? ...

How to set backcolour
Hello All I have a continuous form containing a number field (long integer) called [v_colour]. This field contains the number of a certain colour - as per the numbers that are used in the format properties for back colour etc. I would like to set the back colour for the form's [v_colour] text box to be the value of the field: e.g. If the value of [v_colour] in the first record is 255, I want the back colour of the textbox for that record to be bright red. I tried this as the OnLoad event for the form: [v_colour].backcolour = [v_colour].value .... but this resulted in the back colour of...

Applying Percent Decrease Across Set Periods
I have a column which includes dates when items were purchased. I have used the DATEDIF function to find the number of years between that date and today's date. I now want to decrease the purchase amount 10% for every year calculated via the DATEDIF function. Any ideas, is this possible, why can't I think...? -- Hunt&amp;Peck ------------------------------------------------------------------------ Hunt&amp;Peck's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=32961 View this thread: http://www.excelforum.com/showthread.php?threadid=527873 ...

Set Regional Settings but not Language
Hi I have a multi-language APP en-US, es-ES, it-IT I usually change Languages and Locales by using the CultureInfo to switch Languages System.Globalization.CultureInfo myCI = new System.Globalization.CultureInfo("es-ES"); My issue is - what if the user wants to View App in english and use the Regional Options on a PC in say Spain ??? If I change the CultureInfo to en-US then they can view APP in English ( English satelite assemblies) but date and numbers will be in US format If I change the CultureInfo to es-ES then date and numbers will be in Spain forma...

build chart template; then add series one by one
Hello -- This chart will plot data imported from one or more text files. We want 2 buttons on a UserForm which will allow the user to 1 - erase the old chart and build a new chart "structure" 2 - import one series (in text file) at a time and plot it on the chart (this code works) "Structure" means: 1 - rectangle representing the chart area 1 - chart title 3 - Y axis major gridlines 4 - Y axis scale = range 0 to 5 5 - Y axis title blank 6 - X axis scale = blank 7 - X axis title ' "Time in seconds" 9 - no legend I have been able to achieve this result only ...

Work Hours setting excludes specified hours from Scheduling
I am miffed by this problem. I specify a work hour schedule for a user. When I schedule a CRM User as a Resource for a Service in Scheduling of a Service Activity with Requested Time of ASAP and click Find Available Times, the values for Avilable Times returned are outside of the Work Hours I specified for the user and not within the work hours. When I drill into the Work Hours for this User, the Calendar view shows Cross Day rather than 8:00AM - 5:00PM I speciied for work hours and editing the hours reveal the correct hours in the Work Hours. What gives? Never mind. Figured out w...

Reading Pane Settings
I did a search for an answer to this question and have not found one. If I missed an answer already posted, please direct me to the right place. I have Outlook 2007 and set up the "right" reading pane for my e-mail. Now when I go to my calendar it is set up the same way - calendar on the left (same size as the inbox) and then there is a blank space to the right that is the size of the reading pane/preview. To the right is the to-do bar (which I have no problem with). I don't know why there is a reading/preview pane on the calendar when there is nothing to preview, and I...

How do I create a template where the header cannot be changed?
WORD - Not powerpoint I am creating a MS word 2007 template and am having trouble with the headers and footers. I have put a section break in the first page and ticked different first page. How do I lock the headers and footers - if I delete any text between page 1 and two the headers disappear. Can you help? Why not post your question in one of the Word groups, since it's a Word question? -- Echo [MS PPT MVP] http://www.echosvoice.com What's new in PPT 2010? http://www.echosvoice.com/2010.htm Fixing PowerPoint Annoyances http://tinyurl.com/36grcd PowerPoint 2007 ...

Opening Attachments #19
Hi, I have a customer that is using Office 2003 Pro. Everything has been working OK until yesterday. When he tries to open an Excel attachment he gets the error: Can't create file: *filename*. Right-click the folder you want to create the file in, and then properties on the shortcut menu to check your permissions for the folder. If I try and save the file to an alternate place I get the same error? If I open Outlook in safe mode (hold down ctrl and launch the app) it works fine?? Can anyone shed any light on this please? Regards, Stuart Errington. Stuart Errington <stu...

Metrics should include both Open and Closed Year information
For example Total Receivables for Past 12 Months will show nothing for months that have been closed during the GL Year End Close process...This tool doesn't do much good if you can't see the prior year information after the Year End Close process. when I want to see Total Receivables for the Past 12 Months...after the year end close, the Past 12 Months is no longer valid, cause the metric will only show for the months that are in the GL20000 and are in an open year. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the mos...

Outlook "Arrange By" option does not retain its setting
In outlook 2007, I use a custom view for my inbox, and I have the Group By option checked to"Automatically group according to arrangement." This has been workn flawlessly until today, when I realized Outlook did not like a particular mouse click; perhaps I clicked on the border of two options or some other anomoly that caused the window toflash once. The end result was that my Arrange By option changed to "From" when I had previously set it to "Conversation." Now, whenever I hange it backto "Conversation," leave the inbox and come back, ...

How do I set OOR
I have searched the help menu and have had no luck finding out how to set my outlook 200 to send an OOR (Out of Office Reply) Any assistance would be great If you are in an Exchange environment (ask your administrator if you do notknow) you can set the Out of the Office Assistant which is located under Tools. If you are not in an Exchange environment you can create a rule that replies on all e-mails. The downside of this is that you'll have to have your Outlook open all the time for the rules to process. Make sure you set some exceptions (for instance based on the subject field so ...

Opening to a default tab?
Hello, Is there a way to get a workbook to default to a certain tab when opening the file? I noticed that it opens to whatever page was open when last saved but I want it to always open to the first sheet regardless. Any ideas? Thank you in advance, Joe Use the Workbook_open event in ThisWorkbook module or an auto_open macro in a regular module sub auto_open() sheets("mysheet").select end sub -- Don Guillett SalesAid Software donaldb@281.com "Joe" <Joe@home.com> wrote in message news:eZpp9EUKEHA.1312@TK2MSFTNGP12.phx.gbl... > Hello, > > Is there a wa...

interactive buttons, multiple sets
hi folks I'm sure one of you good folks will save my bacon as usual I have a series of websites, all of which exhibit the same odd behavior with interactive buttons. I have a bunch of buttons in the left margin, each of which pulls up ( lets call it ) a chapter, and in each 'chapter' are a number of related pages. On the top of each page is an imbedded page which has 'page numbers' for all the 'pages' in that chapter. So, it's a grid where the 'vertical' buttons in the left margin and the 'horizontal' buttons at the top comb...

Set Focus
I have text box that I input data into and I was wondering if it is possible to set focus to the text box and avoid clicking on the box. I thought the term is Set Focus, but can't find any information or example that would help in doing so. Any help would be appreciated .. PPT 2003. Look at the following page for code to set focus on a text box: http://officeone.mvps.org/vba/activate_shape.html - Chirag PowerShow - View multiple PowerPoint slide shows simultaneously http://officeone.mvps.org/powershow/powershow.html "Phil K" <PhilK@discussions.microsof...

What port need to open to do Syncronization for CRM Outlook Offlin
Hi all, I've never try Outlook Offline Mode. Could someone tell or give me some official informationn about how technically the Go Online work? I mean what services it runs, through which port... Thank you. Hi, You can take a look at the below document - that explains quite a bit of how it works. http://www.microsoft.com/downloads/details.aspx?FamilyID=c14ca8de-a452-4c9e-b4c9-1c0a51974528&displaylang=en -- Regards Steen Schl´┐Żter Persson (DK) "dorekofu" <dorekofu@discussions.microsoft.com> wrote in message news:0EC2600D-D1D2-416C-A349-16FF9DAC9377@microsoft....

Set published amount of calendar information
Hey guys! Is there any way I can have Exchange 2000/2003 force the amount of time published in the outlook calendar? I know that you can go into the the calendar options and set the amount you want published, but is there a way to have exchange require the amount that is published so that I could get everyone to publish a year's worth of calendar data instead of one person being set at 2 months and another at 6 months and another at 12? Thanks! Mike On Thu, 29 Jun 2006 06:18:02 -0700, Mike <Mike@discussions.microsoft.com> wrote: >Hey guys! > >Is there any way I c...

Form not opening in Datasheet view via the switchboard
I have a form that is to display a table in datasheet view. It works fine when I click it directly i.e. it opens in datasheet view. Unfortunately when I try to open it via the switchboard thru a button it opens the form in form view. Could someone assist I think I might need to write "datasheet" in the event procedure. Thanks! MSA "MSA" <MSA@discussions.microsoft.com> wrote in message news:47FDC06F-A8D5-47E5-8E3E-7787C56838A8@microsoft.com... >I have a form that is to display a table in datasheet view. It works fine > when I click it directly i.e. it open...

automatically open last email when starting outlook
want to turn it off, cant find the checkbox to do it, know its there. "bpaterson" <bpaterson@discussions.microsoft.com> wrote in message news:9662D299-D45C-40B6-A50A-74D61C661874@microsoft.com... > want to turn it off, cant find the checkbox to do it, know its there. Are you saying that when you start Outlook, two windows open, one for the Outlook main window and another for the most recent message in the Inbox? -- Brian Tillman [MVP-Outlook] bpaterson wrote: > want to turn it off, cant find the checkbox to do it, know its there. Whether you use ...

Publisher 2003 Need to set business card to Avery 5371 setting
I need to set the print settings so the business cardd that I created will print on Avery 5371 business cards Okay.........and your question is? -- JoAnn Paules MVP Microsoft [Publisher] "Jonathan" <Jonathan @discussions.microsoft.com> wrote in message news:187615DD-9EF1-42A2-8436-78E6E6C6ACE4@microsoft.com... >I need to set the print settings so the business cardd that I created will > print on Avery 5371 business cards Page setup, business cards, click change copies per sheet, type > .5 top, .75 side, zero gaps. Avery 5371 is a standard business card s...