VBA Error - 'Object doesn't support this property or method' - HELP???

BrianG86

Board Regular
Joined
Nov 12, 2013
Messages
135
Hi,

I have a workbook that I have users fill out and submit to a master file that holds all of the data.

I am getting the above error, but cannot figure out what I am doing wrong. Can anyone help?

Cheers

My code:

Code:
Sub CallLogger()
 
Dim wb As Workbook, twb As Workbook
Dim ws As Worksheet
Dim tws, tws2 As Worksheet
Dim lRow As Long
 
           ' On Error GoTo errhandle
           
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set twb = ThisWorkbook
Set tws = twb.Sheets(1)
Set tws2 = twb.Sheets(2)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
 
                    Application.ScreenUpdating = False
 
Set wb = Workbooks.Open("S:\JL\Common\Model Office Pilot 2016\Model Office Data.xlsx", UpdateLinks:=3, WriteResPassword:="Insight1", IgnoreReadonlyRecommended:=True)
If wb.ReadOnly Then
wb.Close False
MsgBox "The spreadsheet is busy, please try again."
Exit Sub
Else
Set ws = wb.Sheets(1)
 
End If
 
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
lRow = ws.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
 
 
 
    ws.Cells(lRow, 1).Value = tws.Cells(1, 6).Value
    ws.Cells(lRow, 2).Value = tws.Cells(7, 6).Value
    ws.Cells(lRow, 3).Value = tws.Cells(9, 6).Value
    ws.Cells(lRow, 4).Value = tws.Cells(11, 6).Value
    ws.Cells(lRow, 5).Value = tws.Cells(13, 6).Value
    ws.Cells(lRow, 6).Value = tws.Cells(15, 6).Value
    ws.Cells(lRow, 7).Value = tws.Cells(17, 6).Value
    ws.Cells(lRow, 8).Value = Application.UserName
 
Application.Wait (Now + TimeValue("0:00:01"))
 
        Application.CutCopyMode = False
        wb.Close True
 
 
 
 
 
                    Application.ScreenUpdating = True
       
MsgBox "Your entry has been submitted"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
tws.Cells(7, 6).ClearContents
tws.Cells(9, 6).ClearContents
tws.Cells(11, 6).ClearContents
tws.Cells(13, 6).ClearContents
tws.Cells(15, 6).ClearContents
tws.Cells(17, 6).ClearContents
 
Exit Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
errhandle:
If Not wb Is Nothing Then
wb.Close False
Else
End If
MsgBox "There has been an error, please try again"
 
End Sub
 
Hi,

I have fixed it, but I don't know why it wasn't working in the first place.

I noticed that when setting the other sheets as variables it worked fine, so I changed the below line:

Code:
Set tws = twb.Sheets(1)

to

Code:
Set tws = twb.Sheets("Sheet1")

But don't really understand why it works now, when it didn't a minute ago?
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
That suggests to me that the first sheet in ThisWorkbook is not a worksheet.

I thought it might be a chart sheet as that would be the most likely but there are other types of sheet, eg dialog sheets.

What do you get if you type this in the immediate window?
Code:
? TypeName(ThisWorkbook.Sheets(1))
 
Upvote 0
Ahhhh....

So, yes. It was a chart. Turns out there was a hidden sheet that I wasn't aware of.

Thanks
 
Upvote 0

Forum statistics

Threads
1,215,463
Messages
6,124,963
Members
449,200
Latest member
indiansth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top