XL2000 : Comment utiliser les macros pour la hauteur de ligne de jeu et de largeur de colonne

Numéro d'article: 213422 - Voir les produits auxquels s'applique cet article
Agrandir tout | Réduire tout

Résumé

Microsoft Excel utilise la police assignée dans le style Normal comme base pour la largeur des colonnes. Il est inutile de directe pour affecter des largeurs de colonne exacte en pouces ou centimètres sans essais.

Excel base sa mesure de la largeur des colonnes sur le nombre de chiffres (en particulier, le nombre de zéros) dans la colonne, à l'aide de la police du style Normal. (Qu'il y a certaines polices ont des chiffres de différentes largeurs, mais cela est rare).

Par exemple, à l'aide de la police par défaut, une colonne avec une largeur de 10 fait référence à la largeur de colonne nécessaire pour afficher les 10 non gras, non italique Arial 10 points zéros. Sur un ordinateur Macintosh, cette même largeur de colonne se compose de Genève non gras, italique non 10 zéros de 10 points. Excel utilise des chiffres afin de déterminer des largeurs de colonne lorsque vous modifiez la police pour un style dans une feuille de calcul, les colonnes s'agrandissent ou se réduisent à afficher le nombre de chiffres spécifié dans la colonne.

Notez que cette méthode de détermination des largeurs de colonne n'est pas exacte lorsque vous utilisez d'autres caractères, tels que des espaces, signes dollar, parenthèses et ainsi de suite.

Cet article fournit des exemples Microsoft Visual Basic de macros pour applications qui vous permettent de définir la largeur de colonnes et la hauteur de ligne en pouces ou centimètres.

Plus d'informations

Microsoft fournit des exemples de programmation à des fins d'illustration uniquement, sans garantie expresse ou implicite, y compris, sans que cela soit limitatif, les garanties implicites de qualité marchande et/ou d'adéquation à un usage particulier. Cet article suppose que vous connaissez le langage de programmation présenté et les outils utilisés pour créer et déboguer des procédures. Les techniciens du support technique Microsoft peuvent vous aider à comprendre la fonctionnalité d'une procédure particulière, mais ils ne modifieront pas ces exemples pour fournir des fonctionnalités supplémentaires ou créer des procédures répondant à vos besoins spécifiques.
Si vous ne maîtrisez que partiellement la programmation, il convient contacter un partenaire certifié Microsoft ou les services de conseil Microsoft. Pour plus d'informations, visitez ces sites Web de Microsoft :

Microsoft certifié partners - https://partner.microsoft.com/global/30000104

Avis de Microsoft Services - http://support.microsoft.com/gp/advisoryservice

Pour plus d'informations sur les options de support technique disponibles et sur la façon de contacter Microsoft, reportez-vous au site Web de Microsoft à l'adresse suivante : http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMSVisual Basic pour applications macros suivant permet de spécifier les largeurs de ligne et de colonne en pouces.
Sub RowHeightInInches()
    Dim inches As Single
    ' Get the desired column width.
    inches = Application.InputBox("Enter Row Height in Inches", _
        "Row Height (Inches)", Type:=1)
    ' If the cancel button was not pressed.
    If inches Then
        ' Convert and set the column height.
        Selection.RowHeight = Application.InchesToPoints(inches)
    End If
End Sub
				
Sub ColumnWidthInInches()
    Dim inches As Single, points As Integer, savewidth As Integer
    Dim lowerwidth As Integer, upwidth As Integer, curwidth As Integer
    Dim Count As Integer

    ' Turn screen updating off.
    Application.ScreenUpdating = False
    ' Ask for the desired width in inches.
    inches = Application.InputBox("Enter Column Width in Inches", _
        "Column Width (Inches)", Type:=1)
    ' If the cancel button for the input box is pressed, exit the
    ' procedure.
    If inches = False Then Exit Sub
    ' Convert the entered inches to points.
    points = Application.InchesToPoints(inches)
    ' Save the current column width setting.
    savewidth = ActiveCell.ColumnWidth
    ' Set the column width to the maximum allowed.
    ActiveCell.ColumnWidth = 255
    ' If points wanted is greater than points for 255 characters.
    If points > ActiveCell.Width Then
        ' Display a message box (the specified size is too large), and
        ' let user know maximum allowed value.
        MsgBox "Width of " & inches & " is too large." & Chr(10) & _
            "The maximum value is " & Format(ActiveCell.Width / 72, _
            "0.00"), vbOKOnly + vbExclamation, "Width Error"
        ' Reset the column width back to the original.
        ActiveCell.ColumnWidth = savewidth
        ' Exit out of the Sub from here.
        Exit Sub
    End If
    ' Set the lowerwidth and upperwidth variables.
    lowerwidth = 0
    upwidth = 255
    ' Set the column width to the middle of the allowed character range.
    ActiveCell.ColumnWidth = 127.5
    curwidth = ActiveCell.ColumnWidth
    ' Set the count to 0 so if it can't find an exact match it won't go
    ' indefinitely.
    Count = 0
    ' Loop as long as the cell width is different from width desired
    ' and the count (iterations) of the loop is less than 20.
    While (ActiveCell.Width <> points) And (Count < 20)
        ' If active cell width is less than desired cell width.
        If ActiveCell.Width < points Then
            ' Reset lower width to current width.
            lowerwidth = curwidth
            ' Set current column width to the midpoint of curwidth and
            ' upwidth.
            Selection.ColumnWidth = (curwidth + upwidth) / 2
            ' If active cell width is greater than desired width.
        Else
           ' Set upwidth to the curwidth.
           upwidth = curwidth
           ' Set column width to the mid point of curwidth and lower
           ' width.
           Selection.ColumnWidth = (curwidth + lowerwidth) / 2
        End If
        ' Set curwidth to the width of the column now.
        curwidth = ActiveCell.ColumnWidth
        ' Increment the count counter.
        Count = Count + 1
    Wend
End Sub

				
Utilisez les macros suivantes pour spécifier les largeurs de ligne et de colonne en centimètres.
Sub RowHeightInCentimeters()
    Dim cm As Single
    ' Get the row height in centimeters.
    cm = Application.InputBox("Enter Row Height in Centimeters", _
        "Row Height (cm)", Type:=1)
    ' If cancel button not pressed and a value entered.
    If cm Then
        ' Convert and set the row height
        Selection.RowHeight = Application.CentimetersToPoints(cm)
    End If
End Sub
				
Sub ColumnWidthInCentimeters()

    Dim cm As Single, points As Integer, savewidth As Integer
    Dim lowerwidth As Integer, upwidth As Integer, curwidth As Integer
    Dim Count As Integer

    ' Turn screen updating off.
    Application.ScreenUpdating = False
    ' Ask for the width in inches wanted.
    cm = Application.InputBox("Enter Column Width in Centimeters", _
        "Column Width (cm)", Type:=1)
    ' If cancel button for the input box was pressed, exit procedure.
    If cm = False Then Exit Sub
    ' Convert the inches entered to points.
    points = Application.CentimetersToPoints(cm)
    ' Save the current column width setting.
    savewidth = ActiveCell.ColumnWidth
    ' Set the column width to the maximum allowed.
    ActiveCell.ColumnWidth = 255
    ' If the points desired is greater than the points for 255
    ' characters...
    If points > ActiveCell.Width Then
        ' Display a message box because the size specified is too
        ' large and give the maximum allowed value.
        MsgBox "Width of " & cm & " is too large." & Chr(10) & _
            "The maximum value is " & _
            Format(ActiveCell.Width / 28.3464566929134, _
            "0.00"), vbOKOnly + vbExclamation, "Width Error"
        ' Reset the column width back to the original.
        ActiveCell.ColumnWidth = savewidth
        ' Exit the Sub.
        Exit Sub
    End If
    ' Set the lowerwidth and upper width variables.
    lowerwidth = 0
    upwidth = 255
    ' Set the column width to the middle of the allowed character
    ' range.
    ActiveCell.ColumnWidth = 127.5
    curwidth = ActiveCell.ColumnWidth
    ' Set the count to 0 so if it can't find an exact match it won't
    ' go on indefinitely.
    Count = 0
    ' Loop as long as the cell width in is different from width
    ' wanted and the count (iterations) of the loop is less than 20.
    While (ActiveCell.Width <> points) And (Count < 20)
        ' If active cell width is less than desired cell width.
        If ActiveCell.Width < points Then
            ' Reset lower width to current width.
            lowerwidth = curwidth
            ' set current column width to the midpoint of curwidth
            ' and upwidth.
            Selection.ColumnWidth = (curwidth + upwidth) / 2
        ' If active cell width is greater than desired cell width.
        Else
            ' Set upwidth to the curwidth.
            upwidth = curwidth
            ' Set column width to the mid point of curwidth and lower
            ' width.
            Selection.ColumnWidth = (curwidth + lowerwidth) / 2
        End If
        ' Set curwidth to the width of the column now.
        curwidth = ActiveCell.ColumnWidth
        ' Increment the count counter.
        Count = Count + 1
    Wend
End Sub
				

Références

Pour plus d'informations sur la marche à suivre pour obtenir de l'aide concernant Visual Basic pour applications, cliquez sur le numéro ci-dessous pour afficher l'article correspondant dans la base de connaissances Microsoft :
226118OFF2000 : Ressources de programmation pour Visual Basic pour applications

Propriétés

Numéro d'article: 213422 - Dernière mise à jour: jeudi 23 novembre 2006 - Version: 3.5
Les informations contenues dans cet article s'appliquent au(x) produit(s) suivant(s):
  • Microsoft Excel 2000 Standard
Mots-clés : 
kbmt kbdtacode kbhowto kbinfo kbprogramming kbualink97 KB213422 KbMtfr
Traduction automatique
IMPORTANT : Cet article est issu du système de traduction automatique mis au point par Microsoft (http://support.microsoft.com/gp/mtdetails). Un certain nombre d?articles obtenus par traduction automatique sont en effet mis à votre disposition en complément des articles traduits en langue française par des traducteurs professionnels. Cela vous permet d?avoir accès, dans votre propre langue, à l?ensemble des articles de la base de connaissances rédigés originellement en langue anglaise. Les articles traduits automatiquement ne sont pas toujours parfaits et peuvent comporter des erreurs de vocabulaire, de syntaxe ou de grammaire (probablement semblables aux erreurs que ferait une personne étrangère s?exprimant dans votre langue !). Néanmoins, mis à part ces imperfections, ces articles devraient suffire à vous orienter et à vous aider à résoudre votre problème. Microsoft s?efforce aussi continuellement de faire évoluer son système de traduction automatique.
La version anglaise de cet article est la suivante: 213422
L'INFORMATION CONTENUE DANS CE DOCUMENT EST FOURNIE PAR MICROSOFT SANS GARANTIE D'AUCUNE SORTE, EXPLICITE OU IMPLICITE. L'UTILISATEUR ASSUME LE RISQUE DE L'UTILISATION DU CONTENU DE CE DOCUMENT. CE DOCUMENT NE PEUT ETRE REVENDU OU CEDE EN ECHANGE D'UN QUELCONQUE PROFIT.

Envoyer des commentaires