计算字符串中的字符数
Counting the number of characters in a string
我正在尝试使用 Len() 函数从变量中获取字符数,但 vba 说它无法识别它。所以我想知道我的错误是什么,我该如何解决?
Dim y As Long
Dim counthidden As Byte
Dim nbcharac As Long
Dim espace As Long
'boucle sur toutes les diapos à partir de la 2e
For y = 3 To ActivePresentation.Slides.Count
Set Diapo = ActivePresentation.Slides(y)
If Diapo.SlideShowTransition.Hidden = msoTrue Then
counthidden = counthidden + 1
End If
'si la diapo a un titre
If Diapo.Shapes.HasTitle And Diapo.SlideShowTransition.Hidden = msoFalse Then
Set titre = Diapo.Shapes.Title
nbcharac = Len(titre)
espace = 90 - nbcharac
texte_ajout = texte_ajout & titre.TextFrame. _
TextRange.Text & space(espace) & Format(y - counthidden, "0") & vbCrLf
End If
Next y
提前感谢您的帮助
(而且,如果你知道可以放入一个 powerpoint 页面的字符数,尽管我可以测试)
因为 tietre
是一个 Shape
对象而不是字符串,所以 Len
将不起作用。您需要从形状中获取文本来计算长度,例如:
Set titre = Diapo.Shapes.Title
nbcharac = Len(titre.TextFrame.TextRange.Text)
可以通过在模块顶部使用 Option Explicit
来避免很多此类问题,这将强制您显式声明所有变量,例如 tietre
和 Diapo
( Slide
对象),并在编译时显示许多问题,而不是 while 运行.
我正在尝试使用 Len() 函数从变量中获取字符数,但 vba 说它无法识别它。所以我想知道我的错误是什么,我该如何解决?
Dim y As Long
Dim counthidden As Byte
Dim nbcharac As Long
Dim espace As Long
'boucle sur toutes les diapos à partir de la 2e
For y = 3 To ActivePresentation.Slides.Count
Set Diapo = ActivePresentation.Slides(y)
If Diapo.SlideShowTransition.Hidden = msoTrue Then
counthidden = counthidden + 1
End If
'si la diapo a un titre
If Diapo.Shapes.HasTitle And Diapo.SlideShowTransition.Hidden = msoFalse Then
Set titre = Diapo.Shapes.Title
nbcharac = Len(titre)
espace = 90 - nbcharac
texte_ajout = texte_ajout & titre.TextFrame. _
TextRange.Text & space(espace) & Format(y - counthidden, "0") & vbCrLf
End If
Next y
提前感谢您的帮助 (而且,如果你知道可以放入一个 powerpoint 页面的字符数,尽管我可以测试)
因为 tietre
是一个 Shape
对象而不是字符串,所以 Len
将不起作用。您需要从形状中获取文本来计算长度,例如:
Set titre = Diapo.Shapes.Title
nbcharac = Len(titre.TextFrame.TextRange.Text)
可以通过在模块顶部使用 Option Explicit
来避免很多此类问题,这将强制您显式声明所有变量,例如 tietre
和 Diapo
( Slide
对象),并在编译时显示许多问题,而不是 while 运行.