Help with 1004 Error

C

Chris

I am very new to vba and have an issue with a 1004 error when the
workbook is located on a shared drive and more than 1 user opens the
file. My question is if it is possible to make it so:

a) the user cannot overwrite when another user is editing the file.
b) how to get rid of the 1004 debug or end error when a user closes the
file. I tried taking out Active Workbook.save in the Private Sub
Workbook_BeforeClose, but when I do that, I loose the functionality of
the code.

Any help would be most appreciated.

Private Sub Workbook_Open()
Application.ScreenUpdating = False
FrontpageFirst
On Error Resume Next
sStr = fOSUserName()
x = sStr
Select Case x
Case "pmason"
Worksheets("Summary").Visible = True
Worksheets("Key to Abbrvs").Visible = True
Worksheets("Open Positions").Visible = True
Worksheets("Filled Positions").Visible = True
Worksheets("Declined Offers").Visible = True
Worksheets("Current TTRs").Visible = True
Worksheets("Current TOs").Visible = True
Worksheets("On Hold").Visible = True

Case Else
For i = 2 To Worksheets.Count
Worksheets(i).Visible = xlVeryHidden
Next
End Select
Worksheets(2).Activate
Worksheets(1).Visible = xlVeryHidden
Application.ScreenUpdating = False
End Sub

Sub FrontpageFirst()
Dim page As String
page = "Unauthorized"
On Error Resume Next
Worksheets(page).Visible = True
If Worksheets(1).Name = page Then
Worksheets(1).Activate
Else
Worksheets(page).Activate
If Err = 0 Then
ActiveSheet.Move before:=Worksheets(1)
Else
Worksheets.Add before:=Worksheets(1)
Worksheets(1).Name = page
End If
End If
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
FrontpageFirst
For i = 2 To Worksheets.Count
Worksheets(i).Visible = xlVeryHidden
Next
Application.DisplayAlerts = True
ActiveWorkbook.Save
Application.DisplayAlerts = False
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top