Sub macCOPY()
Dim strPath As String
Dim strName As String
Dim wb As Workbook
Dim ws As Worksheet
Dim wkb As Workbook
Dim wks As Worksheet
'turn off events
Call ToggleEvents(False)
'set variables for filepath and file name
strPath = "F:\OpenAccess\Daily_Sales\" '<-- Change to suit
strName = "Orders_Entered_" & Format(Date, "mmddyyyy") & ".xls" '<-- Change to suit
'open the file for that day.
Call OpenWb(strPath, strName)
'set variables for the workbook and worksheet
Set wb = Workbooks("Orders_Entered_" & Format(Date, "mmddyyyy") & ".xls") '<-- Change to suit
Set ws = wb.Sheets(1) '<-- Change to suit
strPath = "F:\OpenAccess\Daily_Sales\" '<-- Change to suit
strName = "OrderEntryTemplate.xlsx" '<-- Change to suit
'Open the table with the current data and copy it into the template
Call OpenWb(strPath, strName)
'set variables for the workbook and worksheet
Set wkb = Workbooks("OrderEntryTemplate.xlsx") '<-- Change to suit
Set wks = wkb.Sheets(2) '<-- Change to suit
'copy cells from the daily excel spreadsheet created
'wb.ws.Cells.Copy
wb.Sheets(1).Cells.Copy
'paste data in the daily template
wkb.Sheets(2).Range("A1").PasteSpecial xlPasteValues '<--Change sheet number to suit
'save the workbook with today's date.
strPath = "F:\OpenAccess\Daily_Sales\" '<--Change to suit
strName = "OrdersEntered_" & Format(Date, "mmddyyyy") & ".xls" '<--Change to suit
wkb.SaveAs strPath & strName, xlNormal
'close the workbooks
wkb.Close
wb.Close
Call ToggleEvents(True)
End Sub
Sub ToggleEvents(blnState As Boolean)
'Originally written by firefytr
With Excel.Application
.DisplayAlerts = blnState
.EnableEvents = blnState
.ScreenUpdating = blnState
If blnState Then .CutCopyMode = False
If blnState Then .StatusBar = False
End With
End Sub
Sub OpenWb(strPath, strName)
'sub created 5/1/2009
'created by Roger Converse
'Check to see if the workbook to be modified is open. If so, create an error message. If not, open the file.
If WbOpen(strPath & strName) = True Then
'error message
MsgBox "This workbook is already open. That should not be the case. If this is a rerun" _
& " then you will need to delete the previous output prior to rerunning.", vbCritical
'turn on events and exit
Call ToggleEvents(True)
Exit Sub
Else
'open the file
Set wb = Workbooks.Open(strPath & strName)
End If
End Sub