Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Saving A File

Hi,

Anyway to save a file using a macro?

Thanks Michael


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default Saving A File

Himszy

I have used the ThisWorkbook object which refers to the workbook containing
the code, but you could use ActiveWorkbook, Workbooks("NameOfBook"),
Workbooks(1)

ThisWorkbook.Save

ThisWorkbook.SaveAs FileName:="xxxxxx.xls"


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS

"Himszy" wrote in message
...
Hi,

Anyway to save a file using a macro?

Thanks Michael




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Saving A File

Thanks Nick
How do you change the path of the file?
Thanks Michael

"Nick Hodge" wrote in message
...
Himszy

I have used the ThisWorkbook object which refers to the workbook

containing
the code, but you could use ActiveWorkbook, Workbooks("NameOfBook"),
Workbooks(1)

ThisWorkbook.Save

ThisWorkbook.SaveAs FileName:="xxxxxx.xls"


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS

"Himszy" wrote in message
...
Hi,

Anyway to save a file using a macro?

Thanks Michael






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default Saving A File

Michael

Saving the file will save it to either the default location (Under
toolsoptionsgeneral) if it's a new book or to the location where the
workbook resides for existing files. If you want to save it elsewhere you
are going to need 'save as' instead of 'save'.

There are tons of ways but if you want to offer a prompt for the user then
use

Sub saveFile()
Dim sFileName As String
sFileName = Application.GetSaveAsFilename()
ThisWorkbook.SaveAs Filename:=sFileName
End Sub

The getsaveasfilename simply presents the save as box and returns the name
and path of the file, you then use that to 'save as' the file.

You could use the hardcode of the file path if it doesn't change, like this.

ThisWorkbook.SaveAs Filename:="C:\" & sFilename

Or you could use the ChDir Statement to change the 'current directory'
ChDir("C:\")

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS

"Himszy" wrote in message
k...
Thanks Nick
How do you change the path of the file?
Thanks Michael

"Nick Hodge" wrote in message
...
Himszy

I have used the ThisWorkbook object which refers to the workbook

containing
the code, but you could use ActiveWorkbook, Workbooks("NameOfBook"),
Workbooks(1)

ThisWorkbook.Save

ThisWorkbook.SaveAs FileName:="xxxxxx.xls"


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS

"Himszy" wrote in message
...
Hi,

Anyway to save a file using a macro?

Thanks Michael








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
Saving Excel 2007 file in 2003 creates very large file Jon Pearce Excel Discussion (Misc queries) 2 July 16th 09 07:20 PM
Saving worksheet in new file with date AND cell value as file name michaelberrier Excel Discussion (Misc queries) 4 May 26th 06 08:05 PM
How do I stop Excel 2000 from saving file history from file that . Cathy Excel Discussion (Misc queries) 0 March 29th 05 03:27 PM
saving an excel file as an ASCII text file without delimiters Sewellst Excel Programming 4 January 7th 05 01:41 PM
Saving a file(new) using the multiple cell contents as a file name Dave Peterson[_3_] Excel Programming 1 August 1st 03 01:40 PM


All times are GMT +1. The time now is 10:56 AM.

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"