Macro runs perfectly on 1 computer but not on another

Flavien

Board Regular
Joined
Jan 8, 2023
Messages
78
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub Generer_Num_FNC_2()

Dim xWb As Workbook
On Error Resume Next
Set xWb = Application.Workbooks.Item(Name)
Dim verification As Boolean
Dim clascompteur As String
Dim Claslauncher As String
estclasseurouvert = (Not xWb Is Nothing)
Dim Wb As Workbook
Dim LADATE As Date
Dim v As Variant


Claslauncher = "P:\01-Qualité\K - Qualité Usinage\00 - Modèle\" & "Left(chemin, pos - 1)" & ".xlsm" 'Essai avec Left... entre guillemets
clascompteur = "P:\01-Qualité\K - Qualité Usinage\00 - Modèle\COMPTEUR.xlsm"


'   figer l'écran
    Application.ScreenUpdating = True
   
'   1ere étape: récupérer le nom de ce classeur

    chemin = ActiveWorkbook.Name
    pos = InStr(chemin, ".xlsm")
'   MsgBox Left(chemin, pos - 1) ' La fonction left permet de retourner que le nom du classeur, sans son extension


'   Déverrouiller l'onglet "Formulaire"
    Workbooks(chemin).Activate
    Sheets("Formulaire").Unprotect Password:="gnt"

'    vérifier si classeur "Compteur" existe
    If Len(Dir(clascompteur)) = 0 Then
        MsgBox "ERREUR: Le classeur Compteur n'existe pas"
            Exit Sub

'   Else 'MsgBox "Le classeur existe"
    End If

'   vérifier si classeur "Compteur" est ouvert

    verification = estclasseurouvert(clascompteur)
    If verifiation = False Then 'false = classeur fermé; True = classeur ouvert
        'MsgBox "cliquer OK pour ouvrir le classeur compteur"

    Else

        MsgBox "Un autre utilisateur utilise déjà le compteur. Veuillez recommencer"

    End If




On Error GoTo Invalid:


    Workbooks.Open Filename:=clascompteur
    ActiveWorkbook.RunAutoMacros xlAutoOpen
'    Workbooks("COMPTEUR").Sheets("Feuil1").Range("E2").Copy
    v = Workbooks("COMPTEUR").Sheets("Feuil1").Range("E2")
 
 
    Workbooks(chemin).Activate
'    Sheets("Formulaire").Visible = True
    Workbooks(chemin).Worksheets("Formulaire").Range("FNC_Num") = v

   
'    Selection.Paste
'    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Workbooks("COMPTEUR").Activate
    Workbooks("COMPTEUR").Close savechanges = True


    Workbooks(chemin).Activate
   
   
'   Insérer la date du jour dans la cellule "Date_Rédaction" & "Date_Détection"

LADATE = Date

Range("Date_Rédaction") = Format(LADATE, "DD/MM/YYYY")  'WW renvoie numéro de semaine
Range("Date_Détection") = Format(LADATE, "DD/MM/YYYY") 'WW renvoie numéro de semaine
   
    Sheets("Formulaire").Protect Password:="gnt"
    Worksheets("Formulaire").Activate
    Worksheets("Formulaire").Range("Criticité").Select
   

'   Rafraichir l'écran
    Application.ScreenUpdating = True

    Exit Sub
   
Invalid:
    MsgBox ("Cliquez une deuxième fois, ça va marcher")
'   Retourner à l'onglet "Accueil"
    Sheets("Accueil").Activate
    Range("A1").Select


End Sub
Hello everybody!
Happy New Year!


The code below opens a "counter" workbook that runs in autorun. Each time you open it, the workbook counter increases. The code copies and pastes the new value. Everything is fine on my computer, but not on my colleague's. It seems to me that the default line would be as follows:

Workbooks.Open Filename:=clascompteur
ActiveWorkbook.RunAutoMacros xlAutoOpen
v = Workbooks("COMPTEUR").Sheets("Feuil1").Range("E2")


Workbooks(chemin).Activate
Workbooks(chemin).Worksheets("Formulaire").Range("FNC_Num") = v

Do you have an idea, please?

COMPTEUR.xlsm
ABCDE
1CompteurDateAnnéeMoisN° de FNC
245002/01/20242024124-01-0450
Feuil1
Cell Formulas
RangeFormula
B2B2=TODAY()
C2C2=YEAR(B2)
D2D2=MONTH(B2)
E2E2=CONCATENATE(RIGHT(C2,2),"-",REPT(0,2-LEN(D2))&D2,"-",REPT(0,4-LEN(A2))&A2)
Named Ranges
NameRefers ToCells
Counter=COMPTEUR[Compteur]E2


LAUNCHER_20.xlsm
AFGHKLMNOPQ
3FNC N°Niveau de criticité (Liste déroulante)OF N°Code articleMoment de détectionDate de détection (Si différent corriger)Type de défaut (Liste déroulante)Défaut ou Non-Conformité constatéQté de pièces NCQté totale de pièces servies sur l'OFQuantité d'OF à sécuriser à votre ilot?
4
Formulaire
Cells with Data Validation
CellAllowCriteria
M4List=INDIRECT("ListeDéfauts")
F4List=INDIRECT("NiveauCriticité")


Thanx a lot for your help!
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Not sure if it would be this, but have you checked that the second computer has the same resources under Tools -> References in the code view?
 
Upvote 0
What precisely goes wrong?
Hi,

There is no error message., and I compared the security settings of both Excel, but there is no difference. Also, the code is read on both computers, so I guess the problem is with the "copy/paste" line of code being misinterpreted, but maybe I'm wrong.


The code should copy the value entered in Workbooks("COMPTEUR").Sheets("Feuil1").Range("E2") and paste it into cell Workbooks(chemin).Worksheets("Formulaire").Range("A4") (A4 = "FNC_Num" and chemin is the name of the active workbook (Launcher_XX).

Unfortunately, on my colleague's PC, the code doesn't copy the value.
I tried this formula

Workbooks("COMPTEUR").Worksheets("Feuil1").Range("E2").Copy Destination: Workbooks(chemin).Worksheets("Formulaire").Range("A4").paste

But it pastes the formula, not the value.
 
Upvote 0
Firstly get rid of this line
VBA Code:
On Error Resume Next
It's why you don't get any errors & makes it impossible to tell what's going on.
Secondly try adding the file extension to this Workbooks("COMPTEUR")
 
Upvote 0
Solution
To paste a value, use paste-special (untested):
VBA Code:
Workbooks("COMPTEUR").Worksheets("Feuil1").Range("E2").Copy 
Workbooks(chemin).Worksheets("Formulaire").Range("A4").pasteSpecial xlPasteValues
 
Upvote 0
Not sure if it would be this, but have you checked that the second computer has the same resources under Tools -> References in the code view?
Do you have a screenshot so I can be sure not to confuse it with anything else?
 
Upvote 0
Thank you jkpieterse, Fluff for your help, it works! I have used both of your proposals!

 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top