{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreigobme4jfnepoc6vnpdgmhbumt57kzrhksdeasxr5hbjm4j4u5wea",
"uri": "at://did:plc:vyjlfm46mfv6u4vjp6qtrfx2/app.bsky.feed.post/3mjx3bld6cie2"
},
"coverImage": {
"$type": "blob",
"ref": {
"$link": "bafkreidg2k33tiuupnstmiowh7hyyvtsbe3gyhfygiytrzynysnhoctrxi"
},
"mimeType": "image/jpeg",
"size": 81260
},
"path": "/articles/good-etiquette",
"publishedAt": "2026-04-20T06:30:00.000Z",
"site": "https://thedailywtf.com",
"tags": [
"CodeSOD",
"Learn more."
],
"textContent": "\"Here, you're a programmer, take this over. It's business critical.\"\n\nThat's what **Felicity** 's boss told her when he pointed her to a network drive containing an Excel spreadsheet. The Excel spreadsheet contained a pile of macros. The person who wrote it had left, and nobody knew how to make it work, but the macros in question were absolutely business vital.\n\nAlso, it's in French.\n\nWe'll take this one in chunks. The indentation is as in the original.\n\n\n Public Sub ExporToutVersBaseDonnées(ClasseurEnCours As Workbook)\n Call AffectionVariables(ToutesLesCellulesNommées)\n Call AffectationBaseDonnées(BaseDonnées)\n BaseDonnées.Activate\n\n\nThe procedures `AffectionVariables` and `AffectationBaseDonnées` populate a pile of global variables. \"base de données\" is French for database, but don't let the name fool you- anything referencing \"base de données\" is referencing another Excel file located on a shared server. There are, in total, four Excel files that must live on a shared server, and two more which must be in a hard-coded path on the user's computer.\n\nOh, and the shared server is referenced not by a hostname, but by IP address- which is why the macros were breaking on everyone's computer; the IP address changed.\n\nLet's continue.\n\n\n 'Vérifier si la ligne existe déjà.\n If ClasseurEnCours.Sheets(\"DATA\").Range(\"Num_Fichier\") = 0 Then\n Num_Fichier = BaseDonnées.Sheets(1).Range(\"Dernier_Fichier\").Value + 1\n Insérer_Ligne: '(étiquette Goto) insérer une ligne\n Application.GoTo Reference:=\"Dernière_Ligne\"\n Selection.EntireRow.Insert\n 'Copie les cellules (colonne A à colonne FI) de la ligne au-dessus de la ligne insérée.\n With ActiveCell\n .Offset(-1, 0).Range(\"A1:FM1\").Copy\n 'Colle le format de la cellule précédemment copiée à la cellule active puis libère les données du presse papier\n .PasteSpecial\n .Range(\"A1:FM1\").Value = \"\"\n 'Se repositionne au début de la ligne insérée.\n .Range(\"A1\").Select\n End With\n Application.CutCopyMode = False\n\n\nUh oh, `Insérer_Ligne` is a label for a `Goto` target. Not to be confused by the `Application.GoTo` call on the next line- that just selects a range in the spreadsheet.\n\nAfter that little landmine, we copy/paste some data around in the sheet.\n\nThat's the `If` side of the conditional, let's look at the `else` clause:\n\n\n Else\n Cherche_Numéro_Fichier: ' Chercher la ligne ou le numéro de fichier est égale à NumFichier.\n While ActiveCell.Value <> Num_Fichier\n If ActiveCell.Row = Range(\"Etiquettes\").Row Then\n GoTo Insérer_Ligne\n End If\n ActiveCell.Offset(-1, 0).Range(\"a1:a1\").Select\n Wend\n 'Vérifier le numéro d'indice de la ligne active.\n If Cells(ActiveCell.Row, 165).Value <> ClasseurEnCours.Sheets(\"DATA\").Range(\"Dernier_Indice\") Then\n ActiveCell.Offset(-1, 0).Range(\"A1:A1\").Select\n GoTo Cherche_Numéro_Fichier\n End If\n ActiveCell.Offset(0, 0).Range(\"A1:FM1\").Value = \"\"\n End If\n\n\nWe start with another label, and… then we have a `Goto`. A `Goto` which jumps us back into the `If` side of the conditional. A `Goto` inside of a while loop, a while loop that's marching around the spreadsheet to search for certain values in the cell.\n\nAfter the loop, we have _another_ `Goto` which will possibly jump us up to the start of the `else` block.\n\nThe procedure ends with some cleanup:\n\n\n '-----\n ' Do some stuff on the active cell and the following cells on the column\n .-----\n BaseDonnées.Close True\n Set BaseDonnées = Nothing\n End Sub\n\n\nI do not know what this function does, and the fact that the code is largely in a language I don't speak isn't the obstacle. I have no idea what the loops and the gotos are trying to do. I'm not even a \"never use `Goto` ever ever ever\" person; in a language like VBA, it's sometimes the best way to handle errors. But this bizarre time-traveling flow control boggles me.\n\n\"Etiquettes\" is French for \"labels\", and it may be bad etiquette but I've got some four letter labels for this code.\n\n[Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.",
"title": "CodeSOD: Good Etiquette"
}