Problème input box

boulettedu84

XLDnaute Nouveau
Bonjours,
J'ai un petit problème avec une inputbox;
Je dois ouvrir un modèle existant pour en faire une copie et renommer la copie.

je parvient a le faire, cependant lorsque je donne un nom déja existant il se met en défaut.

voici le code que j'utilise:

Sub Rectangle6_Clic()

Nom = InputBox("Nom du client :")
If Nom = "" Then Exit Sub
Sheets("Bon d'intervention").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Nom


End Sub



Merci d'avance pour vos réponses ;)
 

Pierrot93

XLDnaute Barbatruc
Re : Problème input box

Bonjour,

il y a sans doute lieu de vérifier si la feuille existe déjà, regarde ceci si cela peut t'aider :
Code:
Option Explicit
Sub test()
Dim nom As String
nom = InputBox("Nom du client :")
If nom = "" Then Exit Sub
If Not FeuilleExiste(nom) Is Nothing Then Exit Sub
Sheets("Bon d'intervention").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = nom
End Sub
Function FeuilleExiste(f As String) As Worksheet
On Error Resume Next
Set FeuilleExiste = Worksheets(f)
End Function

bonne journée
@+
 

Pierrot93

XLDnaute Barbatruc
Re : Problème input box

Re,

on pourrait également le coder ainsi :
Code:
Option Explicit
Sub test()
Dim nom As String

Do
    nom = InputBox("Nom du client :")
Loop While nom = "" Or Not FeuilleExiste(nom) Is Nothing

Sheets("Bon d'intervention").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = nom
End Sub
Function FeuilleExiste(f As String) As Worksheet
On Error Resume Next
Set FeuilleExiste = Worksheets(f)
End Function

A voir comment tu vois la chose....
 

boulettedu84

XLDnaute Nouveau
Re : Problème input box

erf,
merci d'avoir répondu si rapidement, mais je ne parvient pas à faire fonctionner votre code:s

voici un petit test qui pourra vous faire comprendre ce que je veux faire.
 

Pièces jointes

  • test1.xls
    38.5 KB · Affichages: 53
  • test1.xls
    38.5 KB · Affichages: 55
  • test1.xls
    38.5 KB · Affichages: 55

Pierrot93

XLDnaute Barbatruc
Re : Problème input box

Re,

modifie comme suit :
Code:
Sub Rectangle1_Clic()
Dim nom As String
Do
    nom = Application.InputBox("Nom du client :", , nom)
    If nom = "Faux" Then Exit Sub
Loop While nom = "" Or Not FeuilleExiste(nom) Is Nothing
Sheets("Bon d'intervention").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = nom
End Sub
Function FeuilleExiste(f As String) As Worksheet
On Error Resume Next
Set FeuilleExiste = Worksheets(f)
End Function

bon après midi
@+
 

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
312 493
Messages
2 088 956
Membres
103 990
dernier inscrit
lamiadebz