• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

If File is readonly. Close the workbook

Status
Not open for further replies.

XLacs

New Member
Hi Good People.

I have a simple problem yet I cant manage to solve it.
Hoping someone here can actually help me on this one.

Basically,

I have 2 excel workbook. data source and masterfile.
Datasource is using by multiple user to submit data to the masterfile.
I need to put a restriction on this if they simultaneously submit data to the masterfile.


If the masterfile is open to another user, an error msgbox will appear that the file is in readonly.

My below code does not work.. =(

>>> use code - tags <<<
Code:
Sub Submit()
    Const WB_ARCH_PATH As String = "C:\Users\ChrisLacs\Desktop\Test\"
    Const WB_ARCH_NM As String = "Archive.xlsm"
   
    Dim wsSrc As Worksheet, r As Long, rw As Range, wbArch As Workbook
    Dim wsArch As Worksheet, cDest As Range
   
    Set wsSrc = ThisWorkbook.Sheets("Prod")  'source data sheet
   
  
   
    Set wbArch = Workbooks(WB_ARCH_NM)
  
    If Workbooks("Archive.xlsm").ReadOnly Then
     MsgBox "This workbook is already opened by another user."
     Exit Sub
    
     End If
    
    If wbArch Is Nothing Then Set wbArch = Workbooks.Open(WB_ARCH_PATH & WB_ARCH_NM)
    Set wsArch = wbArch.Worksheets("Master")
    Set cDest = wsArch.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) 'first paste destination
   
    For r = 2 To wsSrc.Cells(Rows.Count, "B").End(xlUp).Row   'loop source rows
        Set rw = wsSrc.Rows(r)
        If rw.Columns("O").Value <> "Submitted" And rw.Columns("J").Value = "Pending" Or rw.Columns("J").Value = "Funded" Then
       
            rw.Cells(2).Resize(1, 9).Copy cDest  'Copy A:C for row `rw`
            rw.Columns("O").Value = "Submitted"  'update to Submitted
            Set cDest = cDest.Offset(1, 0)       'next paste destination
        End If
    Next r
   
    wbArch.Close True 'save changes
   
End Sub
 
Last edited by a moderator:
XLacs
Please, Do not duplicate Your thread
You can continue with Your previous thread
 
Status
Not open for further replies.
Back
Top