create worksheet in a different, open workbook

I have the following that nicely checks whether the workbook is open, opens it.  thenchecks for a particular worksheet.  If it exists, it does give me the debug message I put in.  However, it if does not exist, it stops ath the worksheet add line with a subscript out of range error and I do not understand why.
Public Sub cmdRefreshActiveRatingData_Click()
'First check to see if the file is open and if not, then open.  Then check to see if the
'worksheet DataSource exists in the workbook and if not, create it.  Then query the
'ActiveMasterTempate DataSource worksheet to bring in the Rating data
Dim wks As Worksheet
strFileExportPathSumm = ThisWorkbook.Worksheets("Settings").Range("FOLDER_PATH_SUMMARY") ' Summary Reports/General Folder, Range name on Settings worksheet, Settings!$I$5

    If Not fntIsWbkOpen("TEST_ClientActiveMasterTemplate.xls") Then
        Application.Workbooks.Open (strFileExportPathSumm & "TEST_ClientActiveMasterTemplate.xls")
    End If
    Workbooks("TEST_ClientActiveMasterTemplate.xls").Activate
    If fntDoesSheetExist(Workbooks("TEST_ClientActiveMasterTemplate.xls"), "DataSource") Then
        MsgBox "Yes, wks exists.", vbOKOnly
    Else
        MsgBox "No', wks does not exit.", vbOK
    'Get Subscript ouf of range here???
        Workbooks("TEST_ClientActiveMasterTemlate.xls").Worksheets.Add().Name = "DataSource"
    End If

End Sub

Open in new window

Sandra SmithRetiredAsked:
Who is Participating?
 
Rory ArchibaldConnect With a Mentor Commented:
You misspelled the workbook name. Change:
Workbooks("TEST_ClientActiveMasterTemlate.xls").Worksheets.Add().Name = "DataSource"

Open in new window

to:
Workbooks("TEST_ClientActiveMasterTemPlate.xls").Worksheets.Add().Name = "DataSource"

Open in new window

0
 
Saqib Husain, SyedEngineerCommented:
change

        Workbooks("TEST_ClientActiveMasterTemlate.xls").Worksheets.Add().Name = "DataSource"

to

        Workbooks("TEST_ClientActiveMasterTemlate.xls").Worksheets.Add
       activesheet.Name = "DataSource"
0
 
McOzCommented:
The workbook name you are referring to does not exist (misspelled):
'Get Subscript ouf of range here???
        Workbooks("TEST_ClientActiveMasterTemlate.xls").Worksheets.Add().Name = "DataSource"

Open in new window


Should be "TEST_ClientActiveMasterTemplate.xls"

Cheers!
0
 
Sandra SmithRetiredAuthor Commented:
Ok, rorya spotted it first!  I will undoubltely have more as this project has got to be on line MOnday and I am running on about 2 hours sleep a night.  I never even noticed this so simple problem.  Am posting a related questions on this project.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.