Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Saving a variable filename

Good day all
I am trying to write a MACRO in Excel 2007 running on XP to automate a file
save as follows:
I want to save the currently active worksheet as a new workbook *.xls or
*.xlsb where €ś*€ť is a volatile filename contained in a cell on the currently
active worksheet, e.g. €śSeptember€ť, €śOctober€ť €¦.
Can anyone help with the code?
Regards
Wes_A

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Saving a variable filename

Anything wrong with your previous post...?


Dim flToSave As String
Dim flName As String
Dim flFormat As Long

flFormat = ActiveWorkbook.FileFormat
flName = ActiveSheet.Range("A1").Text & ".xls"

'If it is same as the current workbook
flToSave = ActiveWorkbook.Path
OR
'If it is a different path assign to that variable
flToSave = "m:\contract"

ActiveWorkbook.SaveAs flToSave & "\" & flName, flFormat
OR
ActiveWorkbook.SaveCopyAs flToSave & "\" & flName



If this post helps click Yes
---------------
Jacob Skaria


"Wes_A" wrote:

Good day all
I am trying to write a MACRO in Excel 2007 running on XP to automate a file
save as follows:
I want to save the currently active worksheet as a new workbook *.xls or
*.xlsb where €ś*€ť is a volatile filename contained in a cell on the currently
active worksheet, e.g. €śSeptember€ť, €śOctober€ť €¦.
Can anyone help with the code?
Regards
Wes_A

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Saving a variable filename

Hi Jacob

Thanks, it was fine but I needed the month as the filename. Also it was
saved in a format not easily recognised by the excel when trying to open it
later.
Thanks again for the help which is much appreciated.

"Jacob Skaria" wrote:

Anything wrong with your previous post...?


Dim flToSave As String
Dim flName As String
Dim flFormat As Long

flFormat = ActiveWorkbook.FileFormat
flName = ActiveSheet.Range("A1").Text & ".xls"

'If it is same as the current workbook
flToSave = ActiveWorkbook.Path
OR
'If it is a different path assign to that variable
flToSave = "m:\contract"

ActiveWorkbook.SaveAs flToSave & "\" & flName, flFormat
OR
ActiveWorkbook.SaveCopyAs flToSave & "\" & flName



If this post helps click Yes
---------------
Jacob Skaria


"Wes_A" wrote:

Good day all
I am trying to write a MACRO in Excel 2007 running on XP to automate a file
save as follows:
I want to save the currently active worksheet as a new workbook *.xls or
*.xlsb where €ś*€ť is a volatile filename contained in a cell on the currently
active worksheet, e.g. €śSeptember€ť, €śOctober€ť €¦.
Can anyone help with the code?
Regards
Wes_A

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Saving a variable filename

Jacob, my code is now as follows:

Dim flToSave As String
Dim flName As String
Dim flFormat As Long
flFormat = ActiveWorkbook.FileFormat
flName = ActiveSheet.Range("$F$3").Text & ".xlsb"
flToSave = "c:\INVENTORY\HISTORIC\DATA"
ActiveWorkbook.SaveAs flToSave & "\" & flName, flFormat

When trying to run it I get an error saying that file cannot be accessed
since it may not exist. The filename being looked for changes each time but
always looks like:

F2E6E900 or OE2BE900 or OE00F900 etc

Any ideas?
"Jacob Skaria" wrote:

Anything wrong with your previous post...?


Dim flToSave As String
Dim flName As String
Dim flFormat As Long

flFormat = ActiveWorkbook.FileFormat
flName = ActiveSheet.Range("A1").Text & ".xls"

'If it is same as the current workbook
flToSave = ActiveWorkbook.Path
OR
'If it is a different path assign to that variable
flToSave = "m:\contract"

ActiveWorkbook.SaveAs flToSave & "\" & flName, flFormat
OR
ActiveWorkbook.SaveCopyAs flToSave & "\" & flName



If this post helps click Yes
---------------
Jacob Skaria


"Wes_A" wrote:

Good day all
I am trying to write a MACRO in Excel 2007 running on XP to automate a file
save as follows:
I want to save the currently active worksheet as a new workbook *.xls or
*.xlsb where €ś*€ť is a volatile filename contained in a cell on the currently
active worksheet, e.g. €śSeptember€ť, €śOctober€ť €¦.
Can anyone help with the code?
Regards
Wes_A

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Saving a variable filename

Check whether your path is valid. "c:\INVENTORY\HISTORIC\DATA" or other wise
it should work fine...I tried the below..

Dim flToSave As String
Dim flName As String
Dim flFormat As Long
flFormat = ActiveWorkbook.FileFormat
flExtn = Mid(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, "."))
flName = ActiveSheet.Range("F3") & flExtn
flToSave = "c:"
ActiveWorkbook.SaveAs flToSave & "\" & flName, flFormat

If this post helps click Yes
---------------
Jacob Skaria


"Wes_A" wrote:

Jacob, my code is now as follows:

Dim flToSave As String
Dim flName As String
Dim flFormat As Long
flFormat = ActiveWorkbook.FileFormat
flName = ActiveSheet.Range("$F$3").Text & ".xlsb"
flToSave = "c:\INVENTORY\HISTORIC\DATA"
ActiveWorkbook.SaveAs flToSave & "\" & flName, flFormat

When trying to run it I get an error saying that file cannot be accessed
since it may not exist. The filename being looked for changes each time but
always looks like:

F2E6E900 or OE2BE900 or OE00F900 etc

Any ideas?
"Jacob Skaria" wrote:

Anything wrong with your previous post...?


Dim flToSave As String
Dim flName As String
Dim flFormat As Long

flFormat = ActiveWorkbook.FileFormat
flName = ActiveSheet.Range("A1").Text & ".xls"

'If it is same as the current workbook
flToSave = ActiveWorkbook.Path
OR
'If it is a different path assign to that variable
flToSave = "m:\contract"

ActiveWorkbook.SaveAs flToSave & "\" & flName, flFormat
OR
ActiveWorkbook.SaveCopyAs flToSave & "\" & flName



If this post helps click Yes
---------------
Jacob Skaria


"Wes_A" wrote:

Good day all
I am trying to write a MACRO in Excel 2007 running on XP to automate a file
save as follows:
I want to save the currently active worksheet as a new workbook *.xls or
*.xlsb where €ś*€ť is a volatile filename contained in a cell on the currently
active worksheet, e.g. €śSeptember€ť, €śOctober€ť €¦.
Can anyone help with the code?
Regards
Wes_A

Reply
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
Converting a Variable Filename to a Constant Filename Magnivy Excel Programming 2 August 15th 06 06:13 PM
Saving FileName Harald Staff Excel Programming 1 April 13th 05 08:50 PM
Saving with date in filename Ben Allen Excel Programming 3 April 26th 04 09:05 AM
Saving filename same as import filename Matt Excel Programming 4 February 24th 04 03:01 PM
Saving Cell value as filename Kathy B Excel Programming 1 July 24th 03 10:59 PM


All times are GMT +1. The time now is 09:51 PM.

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

About Us

"It's about Microsoft Excel"