Hi all,
I would like to pass a worksheet variable to a sub as follows:
However, all I get is an 'Automation Error' when I get to the line 'MsgBox wsStudentDetails2.Cells(1, 3)'
Would really appreciate it if anyone could suggest why!
Many thanks!1947
I would like to pass a worksheet variable to a sub as follows:
Code:
sub InsertData()
Dim wsDetails2 As Worksheet
CopySheetsIntoVariable "Details (Routine 2)", wsDetails2
MsgBox wsDetails2.Cells(1, 3)
end sub
Code:
Sub CopySheetsIntoVariable(sName As String, ByRef ws As Worksheet)
Dim wbTemp As Workbook
Dim sSaveLocation As String
'This routine extracts the file save location from the registry
sSaveLocation = GetSetting("SaveLocation")
'This copies the closed workbooks into the variable
If Dir(sSaveLocation & sName & ".xlsx", vbDirectory) = "" Then
MsgBox "Error - Cannot find the file '" & sName & ".xlsx'. Exiting.", , "File not found"
Else
Set wbTemp = Workbooks.Open(sSaveLocation & sName & ".xlsx")
Set ws = wbTemp.Sheets("Data")
wbTemp.Close
End If
End Sub
However, all I get is an 'Automation Error' when I get to the line 'MsgBox wsStudentDetails2.Cells(1, 3)'
Would really appreciate it if anyone could suggest why!
Many thanks!1947