I am very new to Macros and I am trying to learn from the Internet. I have copied certain codes into a Purchase Order .xlsm document module and it is working good in the server PC. The document when accessed by the network PC's opens only as "read only" document if the master document is open in the Server PC or in other network PC's. On creating a purchase order in any of the network PC's, when the master document is open in other PC's, the completed document is saviing in the master folder of the server PC but the number is not getting updated in the master file in the server PC or in other network PC's. Can someone give a solution? Given below is the Macro Code I am using:
Sub nextPurchaseOrder()
Dim nextPurchaseOrder As Variant
If Range("K3") < 1 Then 'cell in which the Amendment number is stored
Range("Q11").Value = Range("Q11").Value + 1 'cell in which the Purchase Order number is stored
ElseIf Range("K3") > 0 Then
Range("Q12").Value = Range("Q12").Value + 1
End If
End Sub
Sub CopyToExcel()
Dim wbk As Workbook
'from a workbook, multi-user compatible
On Error Resume Next
Set wbk = Workbooks("C:\Documents and Settings\All Users\Documents\Purchase Order\1 PO Macros Master.xlsm")
On Error GoTo 0
If wbk Is Nothing Then
Workbooks.Open ("C:\Documents and Settings\All Users\Documents\Purchase Order\1 PO Macros Master.xlsm")
Set wbk = Workbooks("C:\Documents and Settings\All Users\Documents\Purchase Order\1 PO Macros Master.xlsm")
End If
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
'reopen the workbook
Workbooks.Open Filename:= _
"C:\Documents and Settings\All Users\Documents\Purchase Order\1 PO Macros Master.xlsm", Editable:=True
With ActiveWorkbook.Sheets(wbk) 'update the workbook's current purchaseorder number
NewVal = .Range("Q11").Value 'remember the new number
End With
ActiveWorkbook.Close True 'close the workbook, save changes
.Range("Q11").Value = NewVal 'put new number into current sheet
.Range("Q11") = "Incremented" 'flag the doublecheck cell
Application.ScreenUpdating = True
Application.EnableEvents = True
End If
End With
'normal save continues from here...
End Sub
Sub SavePurchaseOrderWithNewName()
Dim NewFN As Variant
' Copy PurchaseOrder to a new workbook
ActiveSheet.Copy
Range("A1:L61").Formula = Range("A1:L61").Value
Range("A1:Q61").ClearComments
Range("A3:B7").ClearContents
Range("M1:MZ5000").Delete
If Range("K3") < 1 Then
NewFN = "C:\Documents and Settings\All Users\Documents\Purchase Order\Purchase Order - " & Range("H3").Value & ".xlsx"
ElseIf Range("K3") > 0 Then
NewFN = "C:\Documents and Settings\All Users\Documents\Purchase Order\Amendment -PO " & Range("H5").Value & ".xlsx"
End If
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
nextPurchaseOrder
End Sub
Bookmarks