LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.misc
broro183
 
Posts: n/a
Default Macro to create "path" for save


Hi Chris

I know you are happy with what you have but I just saw the syntax for
how to prevent the need of having to...
Chris Wrote:

... reopen the Template file & close the Client's
file at the end of the macro. If they are not needed just delete

them.
There may be a tidier way of doing this but I don't know it.

[/color]

in a recent post by Ron DeBruin
(http://excelforum.com/showthread.php?t=518959) & thought you may like
it to tidy your code up.

With a little adaptation I have incorporated it into your code as
follows:

Sub RevisedSavePayrollForClient()
'to save template file as "\payroll\COMPANY\YEAR\MONTH\file.xls".
Dim TemplateFileFullPath As String 'renamed
Dim TemplateFile As Workbook 'new/redefined variable
Dim ClientFullPathName As String
Dim StartOfPath As String
Dim ClientCompany As String
Dim ClientMonth As String
Dim ClientYear As String
Dim ClientFileName As String

TemplateFileFullPath = ActiveWorkbook.FullName 'renamed
Set TemplateFile = ActiveWorkbook 'new/redefined variable
StartOfPath = "?:\?\"
ClientCompany = Worksheets("?").Range("a1")
ClientMonth = Worksheets("?").Range("A2")
ClientYear = Worksheets("?").Range("A3")
ClientFileName = "?.xls"
ClientFullPathName = StartOfPath & ClientCompany & "\" & ClientYear &
"\" & _
ClientMonth & "\" & ClientFileName

TemplateFile.SaveCopyAs ClientFullPathName 'new line
End Sub

The key is the second last line. This prevents the need for saving the
ClientFullPathName, reopening the Template & then closing the
ClientFullPathName b/c it is all done in the single line
"TemplateFile.SaveCopyAs ClientFullPathName". The new line keeps the
template file open (with no changes being saved to it) & saves the
Client's file in the chosen directory.

Rob Brockett
NZ
Always learning & the best way to learn is to experience...


--
broro183
------------------------------------------------------------------------
broro183's Profile: http://www.excelforum.com/member.php...o&userid=30068
View this thread: http://www.excelforum.com/showthread...hreadid=522105



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can you create a macro on a protected sheet? Felix Excel Discussion (Misc queries) 2 February 23rd 06 12:37 AM
How do I create a macro that will automatically input lines? cporter Setting up and Configuration of Excel 1 February 22nd 06 10:18 AM
Macro to create mulitple files Consulting Joan Excel Discussion (Misc queries) 1 February 8th 06 03:38 AM
create autosum macro along with notation on the side pino Excel Worksheet Functions 0 June 16th 05 09:44 PM
I need step by step instructions to create a macro for 10 imbedde. diana Excel Worksheet Functions 3 January 31st 05 01:56 AM


All times are GMT +1. The time now is 03:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"