Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET General (http://www.xtremevbtalk.com/-net-general/)
-   -   Multiple users updating Excel from windows form (http://www.xtremevbtalk.com/-net-general/328493-multiple-users-updating-excel-windows-form.html)

av123 11-20-2016 11:05 PM

Multiple users updating Excel from windows form
have created a form in Visual Studio 2013 which is used to enter data in Excel by multiple users at same time. It works perfectly fine except if two users open form at the same time or if one has clicked submit and the form is still processing. Then it shows the following error for the other person.


Unhandled exception has occurred in your application. Exception from HRESULT: 0x800A03EC
Any help on how I can rectify this?


Imports excel = Microsoft.Office.Interop.Excel
Imports System.Runtime.InteropServices

Public Class Form1
    Dim xlapp As New excel.Application
    Dim workbook As excel.Workbook
    Dim worksheet As excel.Worksheet

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        workbook = xlapp.Workbooks.Open("2.xlsx")
        xlapp.Visible = False
        worksheet = workbook.Sheets("sheet1")
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If workbook.MultiUserEditing Then
        End If

        Dim row As Long
        Dim alpha As Long = 0
        row = 5
        With worksheet
            Do While .Cells(row, 4).value IsNot Nothing
                row = row + 1

            .Cells(row, 2).value = Me.fname.Text
            .Cells(row, 3).value = Me.lname.Text
            Me.fullname.Text = Me.fname.Text + Me.lname.Text
            .Cells(row, 4).value = Me.fullname.Text
        End With
        xlapp.DisplayAlerts = False
        workbook.SaveAs("2.xlsx", AccessMode:=excel.XlSaveAsAccessMode.xlShared)
    End Sub
End Class

All times are GMT -6. The time now is 10:48 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.