Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default VBA code to write current workbook to file

Does anyone have any sample VBA code which writes
the current workbook into a new Excel file??
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default VBA code to write current workbook to file

Sub NewFile()
ActiveWorkbook.SaveAs ("C:\newfile.xls")
End Sub
--
Gary''s Student - gsnu200909


"Robert Crandal" wrote:

Does anyone have any sample VBA code which writes
the current workbook into a new Excel file??
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default VBA code to write current workbook to file

How can I copy a closed Excel file to a new Excel file??

I just realized that the only problem with the code below is that
all of that VBA code would also be copied into the new file, right??
I'm going to be copying LOTS of closed Excel files to new file
names, and I dont want the new files to have all that VBA code.


"Gary''s Student" wrote in message
...

Sub NewFile()
ActiveWorkbook.SaveAs ("C:\newfile.xls")
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default VBA code to write current workbook to file

Hi Robert

You have mentioned "current workbook" and hence "Gary''s Student"'s response
is around copying the current workbook to a new workbook. If you are looking
at copying a closed workbook to a different name try the conventional
FileCopy method

Filecopy "c:\test1.xls","d:\test2.xls"

Or you can try the FileSystemObject CopyFile Method

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("c:\test1.xls") Then
fso.CopyFile "c:\test1.xls", "d:\destfolder\"
End If

"Robert Crandal" wrote:

How can I copy a closed Excel file to a new Excel file??

I just realized that the only problem with the code below is that
all of that VBA code would also be copied into the new file, right??
I'm going to be copying LOTS of closed Excel files to new file
names, and I dont want the new files to have all that VBA code.


"Gary''s Student" wrote in message
...

Sub NewFile()
ActiveWorkbook.SaveAs ("C:\newfile.xls")
End Sub


.

  #5   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default VBA code to write current workbook to file

And this....

Option Explicit

Sub SaveCurrentWorkBook()

Dim FileName As Variant

'Get the filename
'Returns False if the user cancels the dialog box.
FileName = Application.GetSaveAsFilename _
(FilterIndex:=5, Title:="Save As")

If FileName = False Then
MsgBox "No file was saved."
Exit Sub
End If

'Display full name and path of file selected
MsgBox "Your file will be saved as " & FileName

End Sub


"Robert Crandal" wrote:

Does anyone have any sample VBA code which writes
the current workbook into a new Excel file??
.



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
How to write the code for copying 2 or more sheets to a new workbook at the same time? new.microsoft.com Excel Programming 4 March 21st 06 03:59 AM
Place code from current workbook to new workbook Qaspec Excel Programming 5 June 8th 05 04:12 AM
Application error when attempting to write code to a workbook Jared Excel Programming 1 November 17th 04 08:17 PM
Possible to write VBA code to send out an EMAIL everytime a workbook is opened? Marcello do Guzman[_2_] Excel Programming 4 September 2nd 04 07:59 AM
Write to closed workbook code Todd Huttenstine[_3_] Excel Programming 4 May 4th 04 09:59 AM


All times are GMT +1. The time now is 03:06 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"