AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1719032
Accepted
MyICQ
MyICQ
Asked: 2022-05-03 03:51:17 +0800 CST2022-05-03 03:51:17 +0800 CST 2022-05-03 03:51:17 +0800 CST

Powerpoint 幻灯片(形状)似乎没有从母版继承替代文本

  • 772

我想替换我的 powerpoint 幻灯片中的一个元素,以了解文档属性变量。我确实有宏,它可以工作。

但我不明白为什么要创建幻灯片,并且基于母版没有任何替代文本。主人确实有替代文字。这使我无法遍历属性。

我错过了某个地方的设置吗?


主模板:

显示替代文本的主模板视图

基于此主布局的幻灯片:

基于母版的幻灯片视图,没有替代文本

microsoft-powerpoint vba
  • 3 3 个回答
  • 120 Views

3 个回答

  • Voted
  1. Best Answer
    Steve Rindsberg
    2022-05-04T07:16:06+08:002022-05-04T07:16:06+08:00

    在大多数情况下,不会有多个给定类型(例如标题、副标题等)的母版/布局占位符,因此您可以将幻灯片形状的占位符类型与幻灯片布局的占位符类型相匹配。这是一些示例 VBA:

    Option Explicit
    
    Sub TestThis()
    
        Dim osl As Slide
        Dim osh As Shape
        Dim sTemp As String
        
        For Each osl In ActivePresentation.Slides
            For Each osh In osl.Shapes
               sTemp = MasterAltText(osh)
               If Len(sTemp) > 0 Then
                    MsgBox sTemp
               End If
            Next
        Next
    End Sub
    
    Function MasterAltText(osh As Shape) As String
    
        Dim osl As Slide
        Dim oMasterShape As Shape
        Dim oLayout As CustomLayout
        
        ' Is this actually a placeholder?
        If Not osh.Type = msoPlaceholder Then
            MasterAltText = ""
        End If
        
        Set osl = osh.Parent
        Set oLayout = osl.CustomLayout
        
        For Each oMasterShape In oLayout.Shapes
            If oMasterShape.Type = msoPlaceholder Then
                If oMasterShape.PlaceholderFormat.Type _
                  = osh.PlaceholderFormat.Type Then
                    MasterAltText = oMasterShape.AlternativeText
                    Exit Function
                End If
            End If
        Next
    
        MasterAltText = ""
    
    End Function
    
    • 1
  2. MyICQ
    2022-05-04T00:46:30+08:002022-05-04T00:46:30+08:00

    我对此进行了一些研究,并且不得不得出结论,将幻灯片母版视为每张幻灯片的“模板”确实被打破了。

    显然,母版幻灯片中占位符/文本框架上设置的标签或替代文本的任何属性都不会转移到基于母版的幻灯片中。因此,认为 VBA 代码可以循环基于标签的形状是不可能的 - 除非在每张幻灯片中都设置了属性。

    我发现的一种技巧是使用字体和位置属性。这样,挑出一个形状是相当简单的。

    伴随着一些东西

        For Each processPage In Application.ActivePresentation.Slides
           For Each shapeobj In processPage.Shapes
               If shapeobj.TextFrame.TextRange.Font.Italic <> 0 Then
                   ' found some shape with ITALIC text
                   ' do things to it
               End If
     
               ' check against a const with section position
               '  Global Const sectiontop as Double = 27.95
               ' 
               If Round(shapeobj.TextFrame2.TextRange.BoundTop, 2) = sectiontop Then
                   ' found shape based on position
                   ' do things to it
               End If
            Next  ' shap
        Next 'slide
    
    
    • 0
  3. MyICQ
    2022-05-04T15:01:56+08:002022-05-04T15:01:56+08:00

    这是对我有用的解决方案,灵感来自 Steve Rindsberg。

    我循环遍历与幻灯片关联的主布局中的形状,然后根据形状的一些指纹构建替代文本字典。使用指纹(例如:字体大小、对齐方式、字体颜色......)我可以解决替代文本和标签不会从母版转移到幻灯片的问题。

    我注意到这只适用于占位符。放置在母版幻灯片上的文本框甚至不存在于幻灯片上下文中,因此此处的方法仅在用户不弄乱格式时才有效。

    ''
    ''  inspired by
    ''  https://superuser.com/questions/1719032/powerpoint-slides-shapes-dont-seem-to-inherit-alternative-text-from-master/1719213#1719213
    ''
    Sub updateSlide()
    
    
        Dim osl As Slide
        Dim d As Dictionary   ' need reference to MS scripting library
        
        Dim osh As Shape
        Dim sTemp As String
        Dim mykey As String
        
        Set d = Nothing
        
        ' Set d = New Dictionary
        
        ' loop over every slide
        For Each osl In ActivePresentation.Slides
            '
            ' make a dictionary of customtexts in the master
            '
            Set d = makedictionary(osl.CustomLayout)
        
            ' loop over shapes
            ' and find using properties like size / font...
            For Each osh In osl.Shapes
                  mykey = makeKEY(osh)
                  
                  ' if found, do something with this shape.
                  If Len(d(mykey)) > 0 Then
                    If ActivePresentation.SectionProperties.Count < 1 Then
                       osh.TextFrame.TextRange.Text = "  -  "
                    Else
                       ' can also replace with other presentation data.
                       ' 
                       osh.TextFrame.TextRange.Text = ActivePresentation.SectionProperties.Name(osl.sectionIndex)
                    End If
                  End If
            Next 'shapes
        Next 'slide
    End Sub
    
    
    
    ''
    ''  make a fingerprint of a shape
    ''
    Function makeKEY(oShape As Shape) As String
        ' return some variables from this one
        ' independent of position !
        ' this is like a "fingerprint" of the shape.
        With oShape.TextFrame.TextRange
            ' choose something that is UNIQUE to the shape
            makeKEY = .Font.Name & .ParagraphFormat.Alignment & .Font.Color & .Font.Italic
        End With
    End Function
    
    
    ''
    ''  make a dictionary of shapes with an alternative text.
    ''  so we don't have to loop the same objects many times.
    ''
    
    Function makedictionary(masterslide As CustomLayout) As Dictionary
        ' make a new dict
        Dim d As Dictionary
        Set d = New Dictionary
        Dim mSh As Shape
        
        For Each mSh In masterslide.Shapes
                If Len(mSh.AlternativeText) > 0 Then
                   mykey = makeKEY(mSh)
                   d(mykey) = mSh.AlternativeText
                End If
        Next
        
        Set makedictionary = d
        Set d = Nothing
    
    End Function
    
    
    
    • 0

相关问题

  • 将电子表格导入 Access 时,如何防止 Excel 自动分配数据字段类型?

  • VBA将Excel中两行的多列放在自己的行上

  • 从不同的工作簿vba复制不同的工作表

  • 计算符合多个条件的行数

  • VBA根据文件名重命名工作表

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve