Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy spreadsheet into another file.


Looking for code to:

Copy "Master" spreadsheet to O:\Sales_Tax and rename spreadsheet to
Last Month. (For example February, if I executed the code today)

Thanks,

Met


--
Metrazal
------------------------------------------------------------------------
Metrazal's Profile: http://www.excelforum.com/member.php...o&userid=31648
View this thread: http://www.excelforum.com/showthread...hreadid=518833

  #2   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Copy spreadsheet into another file.

If I understand you correctly, you want to save a copy of the active workbook
with a filename that represents the previous month. If so, this should do it:

Sub SaveCopyAs_LastMonth()
Dim sFileName As String
sFileName = "O:\Sales_Tax" & MonthName(Month(Date) - 1) & ".xls"
ActiveWorkbook.SaveCopyAs sFileName
End Sub

=OR-
Did you want to copy the ActiveSheet into a new workbook and save it? If so,
post back.

Regards,
GS
  #3   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Copy spreadsheet into another file.

Oops! I forgot one separator. Change this line:

sFileName = "O:\Sales_Tax" & MonthName(Month(Date) - 1) & ".xls"

to:

sFileName = "O:\Sales_Tax\" & MonthName(Month(Date) - 1) & ".xls"

Regards,
GS


"GS" wrote:

If I understand you correctly, you want to save a copy of the active workbook
with a filename that represents the previous month. If so, this should do it:

Sub SaveCopyAs_LastMonth()
Dim sFileName As String
sFileName = "O:\Sales_Tax" & MonthName(Month(Date) - 1) & ".xls"
ActiveWorkbook.SaveCopyAs sFileName
End Sub

=OR-
Did you want to copy the ActiveSheet into a new workbook and save it? If so,
post back.

Regards,
GS

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy spreadsheet into another file.


I am looking to save it in an exsisting workbook called
O:\Sales_Tax.xls


Thanks,
Met


--
Metrazal
------------------------------------------------------------------------
Metrazal's Profile: http://www.excelforum.com/member.php...o&userid=31648
View this thread: http://www.excelforum.com/showthread...hreadid=518833

  #5   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Copy spreadsheet into another file.

Okay, I understand now. Here's some code that should work:

Sub MoveSheetsToOtherBook()
' Moves the selected sheet(s) to a specified workbook
' If the workbook isn't open, it opens it.
' If the file doesn't exist, it exits.
' Requires bBookIsOpen(), bFileExists functions

Dim wbkTarget As Workbook, wbkSource As Workbook
Dim Shts As Sheets

Const sPath As String = "O:\"
Const sName As String = "Sales_Tax.xls"

Set wbkSource = ActiveWorkbook 'or ThisWorkbook

'If wbkSource has been saved, you can't move all its sheets.
'If wbkSource was created from a template but not saved yet,
'delete the following line and its corresponding End If.
If Not ActiveWindow.SelectedSheets.Count = ActiveWorkbook.Sheets.Count Then
Set Shts = ActiveWindow.SelectedSheets

'Get a reference to wbkTarget
If Not bBookIsOpen(sName) Then
If bFileExists(sPath & sName) Then
Set wbkTarget = Workbooks.Open(sPath & sName)
Else
MsgBox "The target file does not exist !", vbExclamation + vbOKOnly
Exit Sub
End If
Else
Set wbkTarget = Workbooks(sName)
End If

'Move the sheet(s) to wbkTarget, save & close it.
wbkSource.Sheets(Shts).Move
after:=wbkTarget.Sheets(wbkTarget.Sheets.Count)
With wbkTarget
.Save
.Close
End With
End If

End Sub


Function bBookIsOpen(wbkName) As Boolean
' Checks if a specified workbook is open.
'
' Arguments: wbkName The name of the workbook
'
' Returns: True if the workbook is open

Const sSource As String = "bBookIsOpen()"

Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbkName)
bBookIsOpen = (Err = 0)

End Function


Function bFileExists(fileName As String) As Boolean
' Checks if a file exists in the specified folder
'
' Arguments: fileName The fullname of the file
'
' Returns: TRUE if the file exists

Const sSource As String = "bFileExists()"

On Error Resume Next
bFileExists = (Dir$(fileName) < "")

End Function

'**
Regards,
GS


  #6   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Copy spreadsheet into another file.

Oops! You did say copy, ..not move. -Sorry about not catching that!
Replace MoveSheetsToOtherBook() with this:

Sub CopySheetToOtherBook()
' Copies the active sheet to a specified workbook.
' If the workbook isn't open, it opens it.
' If the file doesn't exist, it exits.
' Requires bBookIsOpen(), bFileExists functions

Dim wks As Worksheet, wbkTarget As Workbook
Dim sNewName As String

Const sPath As String = "O:\"
Const sName As String = "Sales_Tax.xls"

Set wks = ActiveSheet
sNewName = MonthName(Month(Date) - 1)


'Get a reference to wbkTarget
If Not bBookIsOpen(sName) Then
If bFileExists(sPath & sName) Then
Set wbkTarget = Workbooks.Open(sPath & sName)
Else
MsgBox "The target file does not exist !", vbExclamation + vbOKOnly
Exit Sub
End If
Else
Set wbkTarget = Workbooks(sName)
End If

'Move the sheet(s) to wbkTarget, save & close it.
wks.Copy after:=wbkTarget.Sheets(wbkTarget.Sheets.Count)
With wbkTarget
ActiveSheet.Name = sNewName
.Save
.Close
End With

End Sub


Regards,
GS
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy spreadsheet into another file.


Can you explain this? Is this a seperate sub/module? Please advise.

Thanks,

MET


--
Metrazal
------------------------------------------------------------------------
Metrazal's Profile: http://www.excelforum.com/member.php...o&userid=31648
View this thread: http://www.excelforum.com/showthread...hreadid=518833

  #8   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Copy spreadsheet into another file.

Hi Metrazol,

My previous post is a sub, and should be placed in a standard module.
Disregard all previous examples because the last one copies the active sheet
("Master") into your existing file. The comments at the beginning of the
procedure explain what it does, while each process within the procedure has
comment that outline the steps.

Just call the procedure, or assign it to a button. Make sure the "Master"
sheet you want to copy into the other workbook is active. (the one you're
working on)

Regards,
GS


"Metrazal" wrote:


Can you explain this? Is this a seperate sub/module? Please advise.

Thanks,

MET


--
Metrazal
------------------------------------------------------------------------
Metrazal's Profile: http://www.excelforum.com/member.php...o&userid=31648
View this thread: http://www.excelforum.com/showthread...hreadid=518833


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy spreadsheet into another file.


When I input the sub as entered and run it, I get the following error:

Compile Error
Sub or Function not defined

* bBookIsOpen is highlighted


Thanks,
Me

--
Metraza
-----------------------------------------------------------------------
Metrazal's Profile: http://www.excelforum.com/member.php...fo&userid=3164
View this thread: http://www.excelforum.com/showthread.php?threadid=51883

  #10   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Copy spreadsheet into another file.

Hi Met,

As the lead comments in the sub indicate, you still need to use the two
support functions in my other post. Here they are again:

Function bBookIsOpen(wbkName) As Boolean
' Checks if a specified workbook is open.
'
' Arguments: wbkName The name of the workbook
'
' Returns: True if the workbook is open

Const sSource As String = "bBookIsOpen()"

Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbkName)
bBookIsOpen = (Err = 0)

End Function


Function bFileExists(fileName As String) As Boolean
' Checks if a file exists in the specified folder
'
' Arguments: fileName The fullname of the file
'
' Returns: TRUE if the file exists

Const sSource As String = "bFileExists()"

On Error Resume Next
bFileExists = (Dir$(fileName) < "")

End Function

Regards,
Garry


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy spreadsheet into another file.


Done deal...

Thanks..

One more thing:

I need the date to be in the format FEB 2006, I still need the date
to back up one month but abbreviate the date and display the year.

Once again..

Thanks,
Met


--
Metrazal
------------------------------------------------------------------------
Metrazal's Profile: http://www.excelforum.com/member.php...o&userid=31648
View this thread: http://www.excelforum.com/showthread...hreadid=518833

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy spreadsheet into another file.


Done deal...

Thanks..

One more thing:

I need the date to be in the format FEB 2006, I still need the date
to back up one month but abbreviate the date and display the year.

Once again..

Thanks,
Met


--
Metrazal
------------------------------------------------------------------------
Metrazal's Profile: http://www.excelforum.com/member.php...o&userid=31648
View this thread: http://www.excelforum.com/showthread...hreadid=518833

  #13   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Copy spreadsheet into another file.

Hi Met,

Modify as follows:

sNewName = UCase$(left(monthname(month(date)-1),3)) & " " & year(date)

Regards,
Garry


"Metrazal" wrote:


Done deal...

Thanks..

One more thing:

I need the date to be in the format FEB 2006, I still need the date
to back up one month but abbreviate the date and display the year.

Once again..

Thanks,
Met


--
Metrazal
------------------------------------------------------------------------
Metrazal's Profile: http://www.excelforum.com/member.php...o&userid=31648
View this thread: http://www.excelforum.com/showthread...hreadid=518833


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy spreadsheet into another file.


Once again..

Many thanks..


--
Metrazal
------------------------------------------------------------------------
Metrazal's Profile: http://www.excelforum.com/member.php...o&userid=31648
View this thread: http://www.excelforum.com/showthread...hreadid=518833

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 do I copy spreadsheet data as shown to another spreadsheet? trainer07 Excel Discussion (Misc queries) 2 August 7th 06 09:39 PM
In Excel I want to copy text from spreadsheet to spreadsheet Kris Excel Worksheet Functions 3 June 9th 06 07:58 PM
Unable to copy another spreadsheet to the current spreadsheet with rmcompute Excel Programming 2 November 18th 05 01:19 AM
using vba copy data from .csv file into an excel spreadsheet vineeta Excel Programming 1 October 31st 03 12:57 PM
How to open another Excel spreadsheet to copy data into current spreadsheet ? Ricky Pang Excel Programming 0 July 13th 03 01:59 PM


All times are GMT +1. The time now is 01:27 AM.

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"