I am trying to copy one worksheet to the end of another workbook. The target workbook has 23 sheets in it. I am trying to write code that will copy the source worksheet to the end of the workbook. I keep on getting this error. Is there a way of designating what worksheet the new worksheet will go to because there is another project that I have to copy to that is in the middle of the workbook. The error line is highlighted in blue. Any help is appreciated.
Tom
Tom
Code:
Public Function CopyWorksheet(strUCI As String, strSourceSheetName As String, strTargetSheetName As String)
Dim strMon As String
Dim strFileLoc As String
Dim strOpenStdRpt As String
Dim strSql As String
Dim rstMon As Recordset
Dim strMonShort As String
Dim strCurFY As String
Dim strSourceWorkbook As String
Dim strTargetWorkbook As String
Dim strYr As String
Dim strMonNum As String
Dim iMon As Integer
Call CurMonYr(strUCI, strMon, strYr, iMon)
'Find Current Month
strSql = "SELECT mon_txtnum,calpddiff " & _
"FROM dbo_dic_Period " & _
"WHERE calpddiff = 1;"
Set rstMon = CurrentDb.OpenRecordset(strSql, dbOpenSnapshot)
If Not rstMon.EOF Then
With rstMon
.MoveLast
.MoveFirst
End With
End If
'Assign variables for file name and sheetname
strMonNum = rstMon![mon_txtnum]
strFileLoc = "\\salmfilesvr1\Public\Client Services\AutoRpts\_RptSets\SALEM\HMF\" & (strYr) & "\" & (strMonNum) & "\"
strOpenStdRpt = "SECURE EMAIL_HMF_" & (strMon) & "_" & (strYr) & "_Corcoran__Lois_98.xls"
'Open destination workbook
goXl.Workbooks.Open FileName:=strFileLoc & strOpenStdRpt
'Assign Variables for Current workbook name
strSourceWorkbook = "HMF_CPT95951_" & (strMon) & (strYr) & ".xls"
strTargetWorkbook = strOpenStdRpt
'Copy to new sheet
[Blue] goXl.Sheets(strSourceWorkbook).Copy After:=Workbooks(strTargetWorkbook).Sheets(Workbooks(strTargetWorkbook).Sheets.Count) [/Blue]
'Close
goXl.ActiveWorkbook.Close
End Function