Actually it is a template that is opened "Dog", then it opens "Cat" to get
the information from. Dos5 is copied from "Cat" to "Dog". How does this
work where it is a template that is opened and not an actual filename that I
can use?
Here is my code that is stored in the template "Dog":
Private Sub Workbook_Open()
'Dim pathStr As String
'pathStr = "K:\Individual Directories\Woodford, Cathy\Daily Report"
Cells(1, 1).ClearContents
Application.DisplayAlerts = True
UpdateLinks = xlUpdateLinksAlways
If ThisWorkbook.Path = "" Then
Call openfile
End If
'Call openfile
UpdateLinks = xlUpdateLinksAlways
End Sub
Private Sub openfile()
Dim sDailyReport As String
Dim vFileName As Variant
Dim fName As Variant
Dim bk As Workbook
Dim ws As Worksheet
Dim sFilename As String
Dim fileToOpen As Variant
ChDrive "K"
ChDir "K:\Individual Directories\Woodford, Cathy\Daily Report"
fileToOpen = Application.GetOpenFileName("Excel Files (*.xls), *.xls")
If fileToOpen <> False Then
Set bk = Workbooks.Open(FileName:=fileToOpen)
Else
MsgBox "User Clicked Cancel, Exiting"
ThisWorkbook.Close savechanges:=False
Exit Sub
End If
ActiveWindow.WindowState = xlMinimized
ActiveWindow.WindowState = xlMaximized
Sheets(1).Cells(1, 1).Value = Right(fileToOpen, (Len(fileToOpen) -
(InStrRev(fileToOpen, "\"))))
Sheets(2).Cells(1, 1).Value = Right(fileToOpen, (Len(fileToOpen) -
(InStrRev(fileToOpen, "\"))))
Sheets(3).Cells(1, 1).Value = Right(fileToOpen, (Len(fileToOpen) -
(InStrRev(fileToOpen, "\"))))
Sheets(4).Cells(1, 1).Value = Right(fileToOpen, (Len(fileToOpen) -
(InStrRev(fileToOpen, "\"))))
THIS IS WHERE I WAS TRYING TO COPY DOS5
'Copy sheet 5 to new book
bk.Activate
Sheets("DOS5").Select
Sheets("DOS5").Copy After:=Workbooks("template name goes here????").Sheets(4)
'after:=ActiveWorkbook.Sheets("dos5")
'Code that updates the sheets
For Each ws In Worksheets
With ws.Cells
.Copy
.PasteSpecial xlPasteValues
End With
Next ws
'Application.CutCopyMode = False
'Get name for file save
sFilename = ("CNLOPB " & Right(fileToOpen, (Len(fileToOpen) -
(InStrRev(fileToOpen, "\")))))
fName = Application.GetSaveAsFilename(InitialFileName:=sFilename,
filefilter:="Microsoft Excel Files(*.xls),*.xls", Title:="Select a name for
this file")
If fName = False Then
bk.Close
ActiveWorkbook.Close savechanges:=False
ThisWorkbook.Close savechanges:=False
Else
ActiveWorkbook.SaveAs fName
bk.Close savechanges:=False
ThisWorkbook.Close savechanges:=False
End If
End Sub
Cathy