csimarketing
New Member
- Joined
- Jun 18, 2019
- Messages
- 15
- Office Version
- 2019
- Platform
- MacOS
Hello, I am a beginner with macros and am having trouble. I have created a macro that creates a new sequential Invoice number upon opening a protected document. My issue is that several people in the company will be using this same document. How can I make sure that If several people have the document open, they each get a different Invoice number so that they are no duplicate invoice numbers.
Here is the code I currently have that I mentioned above that works, but not if several people try to access the doc:
Private Sub Workbook_Open()
ActiveSheet.Unprotect
With Range("K2")
.NumberFormat = "10000"
.Value = .Value + 1
End With
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Here is the rest of the macros that I created in the document as well, in case they are affecting it somehow:
Sub SaveAsPDF()
'
' SaveAsPDF Macro
'
'
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"/Users/brittneywilliams/Desktop/Quote_" & Range("K2").Text, Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
End Sub
Sub ClearContents()
'
' ClearContents Macro
'
'
Range( _
"E4,H4,J4:K4,C8:J8,C10:D10,F10:G10,I10:J10,C12:E12,I12:J12,C17:F17,J17,C19:J19,C21:F21,J21,C23:F23,I23:J23,C25:J25,C27:D27,G27:H27,C29:D29,C31:F31,C33:J33,C40,F40,I40,C42,F42,I42,C48,F48,I48,H50:J50,H52:J52,C72:J74" _
).Select
Selection.ClearContents
End Sub
Sub ClearCheckBoxes()
'Updateby Extendoffice 20161129
Dim chkBox As Excel.CheckBox
Application.ScreenUpdating = False
For Each chkBox In ActiveSheet.CheckBoxes
chkBox.Value = xlOff
Next chkBox
Application.ScreenUpdating = True
End Sub
Sub ResetValues()
'
' ResetValues Macro
'
'
Range("C38:E38").Select
ActiveCell.FormulaR1C1 = "0"
Range("D40").Select
ActiveCell.FormulaR1C1 = "0"
Range("G40").Select
ActiveCell.FormulaR1C1 = "0"
Range("J40").Select
ActiveCell.FormulaR1C1 = "0"
Range("D42").Select
ActiveCell.FormulaR1C1 = "0"
Range("G42").Select
ActiveCell.FormulaR1C1 = "0"
Range("J42").Select
ActiveCell.FormulaR1C1 = "0"
Range("D48").Select
ActiveCell.FormulaR1C1 = "0"
Range("G48").Select
ActiveCell.FormulaR1C1 = "0"
Range("J48").Select
ActiveCell.FormulaR1C1 = "0"
Range("C72").Select
End Sub
Private Sub RunAllMacros()
Call ClearContents
Call ResetValues
Call ClearCheckBoxes
End Sub
Any help would be much appreciated! Thank you!
Here is the code I currently have that I mentioned above that works, but not if several people try to access the doc:
Private Sub Workbook_Open()
ActiveSheet.Unprotect
With Range("K2")
.NumberFormat = "10000"
.Value = .Value + 1
End With
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Here is the rest of the macros that I created in the document as well, in case they are affecting it somehow:
Sub SaveAsPDF()
'
' SaveAsPDF Macro
'
'
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"/Users/brittneywilliams/Desktop/Quote_" & Range("K2").Text, Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
End Sub
Sub ClearContents()
'
' ClearContents Macro
'
'
Range( _
"E4,H4,J4:K4,C8:J8,C10:D10,F10:G10,I10:J10,C12:E12,I12:J12,C17:F17,J17,C19:J19,C21:F21,J21,C23:F23,I23:J23,C25:J25,C27:D27,G27:H27,C29:D29,C31:F31,C33:J33,C40,F40,I40,C42,F42,I42,C48,F48,I48,H50:J50,H52:J52,C72:J74" _
).Select
Selection.ClearContents
End Sub
Sub ClearCheckBoxes()
'Updateby Extendoffice 20161129
Dim chkBox As Excel.CheckBox
Application.ScreenUpdating = False
For Each chkBox In ActiveSheet.CheckBoxes
chkBox.Value = xlOff
Next chkBox
Application.ScreenUpdating = True
End Sub
Sub ResetValues()
'
' ResetValues Macro
'
'
Range("C38:E38").Select
ActiveCell.FormulaR1C1 = "0"
Range("D40").Select
ActiveCell.FormulaR1C1 = "0"
Range("G40").Select
ActiveCell.FormulaR1C1 = "0"
Range("J40").Select
ActiveCell.FormulaR1C1 = "0"
Range("D42").Select
ActiveCell.FormulaR1C1 = "0"
Range("G42").Select
ActiveCell.FormulaR1C1 = "0"
Range("J42").Select
ActiveCell.FormulaR1C1 = "0"
Range("D48").Select
ActiveCell.FormulaR1C1 = "0"
Range("G48").Select
ActiveCell.FormulaR1C1 = "0"
Range("J48").Select
ActiveCell.FormulaR1C1 = "0"
Range("C72").Select
End Sub
Private Sub RunAllMacros()
Call ClearContents
Call ResetValues
Call ClearCheckBoxes
End Sub
Any help would be much appreciated! Thank you!