2014-04-23 60 views
0

我有一个设置,其中多个用户输入表单(“输入”工作簿)中的数据,将数据复制到另一个工作簿(“数据”工作簿)。如果两个用户试图同时更新数据,则会出现错误。 “数据”工作簿保持打开状态,从而阻止来自其他用户的更新选项。如果Excel文件打开,显示消息框和结束表格

我想要一个消息框说:“使用中的工作簿,请再试一次”,此后“数据”工作簿关闭,用户再次从窗体发送数据,但我似乎无法让它工作。

有人请给我一些关于如何解决这个问题的指针?

这里是从输入表格的代码从“输入”工作簿:“允许在同一时间由一个以上的用户的变化”

Private Sub CmdButton_add_Click() 

Dim wbk As Workbook 
Set wbk = Workbooks.Open("G:\afregsyd\KSC SYD\Salgsregistrering\indtastninger2.xlsx") 
Dim iRow As Long 
Dim ws As Worksheet 
Set ws = Worksheets("Ark1") 

'find first empty row in database 
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1 

'check for a Name number 
If Trim(Me.TextBox_Initialer.Value) = "" Then 
Me.TextBox_Initialer.SetFocus 
MsgBox "Please complete the form" 
Exit Sub 
End If 

'copy the data to the database 
ws.Cells(iRow, 1).Value = Date 
ws.Cells(iRow, 2).Value = Me.TextBox_Initialer.Value 
ws.Cells(iRow, 3).Value = Me.TextBox_Salg.Value 
ws.Cells(iRow, 4).Value = Me.TextBox_Liv.Value 
ws.Cells(iRow, 5).Value = Me.TextBox_Bank.Value 
ws.Cells(iRow, 6).Value = Me.TextBox_Mersalg.Value 

'close Workbook 
ActiveWindow.Close SaveChanges:=True 

MsgBox "Data tilføjet", vbOKOnly + vbInformation, "Data tilføjet" 
'clear the data 
Me.TextBox_Salg.Value = "" 
Me.TextBox_Liv.Value = "" 
Me.TextBox_Bank.Value = "" 
Me.TextBox_Mersalg.Value = "" 
Me.TextBox_Initialer.SetFocus 
End Sub 



Private Sub Cmdbutton_close_Click() 
Unload Me 
End Sub 

回答

0

评分/共享工作簿/编辑/检查

对于使用VBA操作,请参阅从链接http://support.microsoft.com/kb/153058

代码:

Sub Example1() 

    ' Test to see if the Read-only attribute was assigned to the file. 

    If GetAttr("c:\test.xls") And vbReadOnly Then 
    MsgBox "File is Read-only" 
    Else 
    MsgBox "File is not read-only" 
    End If 

End Sub 
相关问题