PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms..win.server.scripting > RE: Adding Excel data validation
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
RE: Adding Excel data validation

Réponse
 
LinkBack Outils de la discussion
Vieux 29/08/2007, 15h56   #1 (permalink)
urkec
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Adding Excel data validation

"Akhil_Bansal20" wrote:

> Hi
>
> I need to add excel data validation (list) to a cell so that when user
> clicks on the cell, he gets a drop down listing all possible values. I can do
> this using VB.net but when i am trying to do it in VB script it is not
> working. The code that I am using is as follows.
>
> Dim objXls
> Dim wrkBook
> Dim wrkSheet
> Dim tmp
> Dim RowRange
> Dim Yes
> Dim No
>
> set objXls = CreateObject("Excel.Application")
> objXls.Visible = True
>
> set wrkBook = objXls.Workbooks.add() ' Open the Workbook
> set wrkSheet = wrkBook.Worksheets(1) ' Get Reference to
> WorkBook
> wrkSheet.Activate()
>
> wrkSheet.Range("A65535") = "yes"
> wrkSheet.Range("A65536") = "No"
>
>
> set tmp = wrkSheet.Range("A65535:A65536")
> set RowRange = wrkSheet.Range("A10")
> RowRange.value="Akhil"
> RowRange.Interior.ColorIndex = 5
> 'msgbox(Excel.XlDVType.xlValidateList)
>
>
> With RowRange.Validation
> .Add(Excel.XlDVType.xlValidateList,
> Excel.XlDVAlertStyle.xlValidAlertStop,
> Excel.XlFormatConditionOperator.xlBetween, "=$A$65535:$A$65536")
> .InCellDropdown = True
> End With
>


In VBScript you need to define Excel costants:


const xlValidAlertStop = 1
const xlBetween = 1
const xlValidateList = 3

set objXls = CreateObject("Excel.Application")
objXls.Visible = True

set wrkBook = objXls.Workbooks.add()
set wrkSheet = wrkBook.Worksheets(1)
wrkSheet.Activate()

wrkSheet.Range("A65535") = "Yes"
wrkSheet.Range("A65536") = "No"

set tmp = wrkSheet.Range("A65535:A65536")
set RowRange = wrkSheet.Range("A1")
RowRange.value="Akhil"
'RowRange.Interior.ColorIndex = 5

With RowRange.Validation
..Add _
xlValidateList, _
xlValidAlertStop, _
xlBetween, _
"=$A$65535:$A$65536"
..InCellDropdown = True
End With

--
urkec
  Réponse avec citation
Vieux 30/08/2007, 05h28   #2 (permalink)
Akhil_Bansal20
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Adding Excel data validation

Hello Urkec,

That was a nice suggestion. I tried but it is not working. I even tried to
add constant in add functions also, but it is not working. Strange thing is
that it is not giving any error also.


"urkec" wrote:

> "Akhil_Bansal20" wrote:
>
> > Hi
> >
> > I need to add excel data validation (list) to a cell so that when user
> > clicks on the cell, he gets a drop down listing all possible values. I can do
> > this using VB.net but when i am trying to do it in VB script it is not
> > working. The code that I am using is as follows.
> >
> > Dim objXls
> > Dim wrkBook
> > Dim wrkSheet
> > Dim tmp
> > Dim RowRange
> > Dim Yes
> > Dim No
> >
> > set objXls = CreateObject("Excel.Application")
> > objXls.Visible = True
> >
> > set wrkBook = objXls.Workbooks.add() ' Open the Workbook
> > set wrkSheet = wrkBook.Worksheets(1) ' Get Reference to
> > WorkBook
> > wrkSheet.Activate()
> >
> > wrkSheet.Range("A65535") = "yes"
> > wrkSheet.Range("A65536") = "No"
> >
> >
> > set tmp = wrkSheet.Range("A65535:A65536")
> > set RowRange = wrkSheet.Range("A10")
> > RowRange.value="Akhil"
> > RowRange.Interior.ColorIndex = 5
> > 'msgbox(Excel.XlDVType.xlValidateList)
> >
> >
> > With RowRange.Validation
> > .Add(Excel.XlDVType.xlValidateList,
> > Excel.XlDVAlertStyle.xlValidAlertStop,
> > Excel.XlFormatConditionOperator.xlBetween, "=$A$65535:$A$65536")
> > .InCellDropdown = True
> > End With
> >

>
> In VBScript you need to define Excel costants:
>
>
> const xlValidAlertStop = 1
> const xlBetween = 1
> const xlValidateList = 3
>
> set objXls = CreateObject("Excel.Application")
> objXls.Visible = True
>
> set wrkBook = objXls.Workbooks.add()
> set wrkSheet = wrkBook.Worksheets(1)
> wrkSheet.Activate()
>
> wrkSheet.Range("A65535") = "Yes"
> wrkSheet.Range("A65536") = "No"
>
> set tmp = wrkSheet.Range("A65535:A65536")
> set RowRange = wrkSheet.Range("A1")
> RowRange.value="Akhil"
> 'RowRange.Interior.ColorIndex = 5
>
> With RowRange.Validation
> .Add _
> xlValidateList, _
> xlValidAlertStop, _
> xlBetween, _
> "=$A$65535:$A$65536"
> .InCellDropdown = True
> End With
>
> --
> urkec

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h50.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08905 seconds with 10 queries