Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VBA Code in Shared Workbooks
Message
Information générale
Forum:
Microsoft Office
Catégorie:
Excel
Divers
Thread ID:
01564375
Message ID:
01564666
Vues:
33
>I have written VBA code in Excel 2010, to lock cells programmatically, under certain conditions. For example, if Column N gets filled in, Columns O, P, and Q should be locked, since they are mutually exclusive. My VBA code also puts user and date stamps in columns that are otherwise locked. I need to make this spreadhseet writable for multiple users at once. However, when I set enable Share Workbook, my VBA code crashes, seemingly because it now can't lock cells and programmatically insert code into locked cells. Is there a way to get around this, such as by programmatically turning Share Workbook on and off as needed, or allowing multiuser editing another way, or allowing my VBA code to do its stuff regardless of the Share Workbook setting?
>
>Here are the relevant parts of my code:
>
>Private Sub Workbook_Open()
> ActiveSheet.Protect UserInterfaceOnly:=True
> gcITNames = (names of applicable users)
> ActiveWorkbook.ActiveSheet.Columns(19).Locked = (Not InStr(gcITNames, Application.UserName + ",") > 0)
>End Sub
>
>Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
> Application.EnableEvents = False
> ActiveWorkbook.ActiveSheet.Cells(x, 14).Locked = (Not (ActiveSheet.Cells(x, 15).Value = "" And ActiveSheet.Cells(x, 16).Value = "" And ActiveSheet.Cells(x, 17).Value = ""))
> ActiveWorkbook.ActiveSheet.Cells(x, 15).Locked = (Not (ActiveSheet.Cells(x, 14).Value = "" And ActiveSheet.Cells(x, 16).Value = "" And ActiveSheet.Cells(x, 17).Value = ""))
> ActiveWorkbook.ActiveSheet.Cells(x, 16).Locked = (Not (ActiveSheet.Cells(x, 14).Value = "" And ActiveSheet.Cells(x, 15).Value = "" And ActiveSheet.Cells(x, 17).Value = ""))
> ActiveWorkbook.ActiveSheet.Cells(x, 17).Locked = (Not (ActiveSheet.Cells(x, 14).Value = "" And ActiveSheet.Cells(x, 15).Value = "" And ActiveSheet.Cells(x, 16).Value = ""))
> If Trim(ActiveSheet.Cells(x, 13).Value) = "" And Not Trim(ActiveSheet.Cells(x, 14).Value) + Trim(ActiveSheet.Cells(x, 15).Value) + Trim(ActiveSheet.Cells(x, 16).Value) + Trim(ActiveSheet.Cells(x, 17).Value) = "" Then
> ActiveSheet.Cells(x, 12).Value = Application.UserName
> ActiveSheet.Cells(x, 13).Value = Date
> ElseIf Not ActiveSheet.Cells(x, 13).Value = "" And Trim(ActiveSheet.Cells(x, 14).Value) + Trim(ActiveSheet.Cells(x, 15).Value) + Trim(ActiveSheet.Cells(x, 16).Value) + Trim(ActiveSheet.Cells(x, 17).Value) = "" Then
> ActiveSheet.Cells(x, 12).Value = ""
> ActiveSheet.Cells(x, 13).Value = ""
> End If
> Application.EnableEvents = True
>End Sub
>
>
>Jerry

I doubt that there is a solution.
As one can read in http://office.microsoft.com/en-us/excel-help/about-shared-workbooks-HP005262294.aspx,

*-----------------------------------
... Because some Microsoft Excel features can be viewed or used but not changed once the workbook is shared, you'll want to set up these features before you share the workbook.

The following features can't be changed after a workbook is shared: merged cells, conditional formats, data validation, charts, pictures, objects including drawing objects, hyperlinks, scenarios, outlines, subtotals, data tables, PivotTable reports, workbook and worksheet protection, and macros.
*-------------------------------------------------

Good Luck
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform