.Close method results in read only

jtdewhurst

New Member
Joined
Jan 16, 2015
Messages
26
Hello,
I'm trying to open, write-to, save, and close a workbook in VBA. I'm using the .close(true) method. I've also tried the following.

Code:
Sub UPDT_DLY_PRDCT_CNT()
    Dim XLapp As New Excel.Application
    Dim ObjXL As Excel.Workbook
    Set ObjXL = XLapp.Workbooks.Open("G:\TAE\Private\Jobs\PW\30K\Production\Engineering\Singlet NCR Tracking\Singlet NCR Tracking.xlsm")
    ObjXL.Sheets("Daily Production Totals").Cells(4, 1).EntireRow.Insert
        Dim k As Integer
        For k = 1 To 3
            ObjXL.Sheets("Daily Production Totals").Cells(4, k).Value = Workbooks("Book1").Sheets("Production History").Cells(4, k).Value
        Next k

    ObjXL.Save
    ObjXL.Close
    XLapp.Quit

End Sub

However, everything I've tried works, but when I go to open the file that I edited, it tells me it is locked for editing. If I open a read only, then exit. I can open it fine the next time. So it seems like the methods are not really closing, and terminating the application.

Any thoughts?

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi,

Did you try to set ObjXL = Nothing after closing?
It might be that the object is still holding the lock to the file untill it is being destroyed.

Paul
 
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

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