ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 357|回复: 2

[求助] 常量代码修改

[复制链接]

TA的精华主题

TA的得分主题

发表于 2023-5-19 08:47 | 显示全部楼层 |阅读模式
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
下面代码中首先申明了一个常量Const k As Integer = 20,

后面模块中引用常量k没有问题,我想让k值等于当前幻灯片放映页面编号,
修改成Const k As Integer = ActiveWindow.Selection.SlideRange.SlideIndex
就没有效果了,请老师们看看如何修改。
Const k As Integer = ActiveWindow.Selection.SlideRange.SlideIndex
代码如下:

’Const k As Integer = 20
Const k As Integer = ActiveWindow.Selection.SlideRange.SlideIndex

Sub 甲1a()
    ActivePresentation.Slides(k).Shapes("答甲1").TextEffect.Text = Mid(ActivePresentation.Slides(k).Shapes("甲1a").TextEffect.Text, 1, 1)
End Sub
Sub 甲1b()
    ActivePresentation.Slides(k).Shapes("答甲1").TextEffect.Text = Mid(ActivePresentation.Slides(k).Shapes("甲1b").TextEffect.Text, 1, 1)
End Sub
Sub 甲1c()
    ActivePresentation.Slides(k).Shapes("答甲1").TextEffect.Text = Mid(ActivePresentation.Slides(k).Shapes("甲1c").TextEffect.Text, 1, 1)
End Sub

Sub 甲2a()
    ActivePresentation.Slides(k).Shapes("答甲2").TextEffect.Text = Mid(ActivePresentation.Slides(k).Shapes("甲2a").TextEffect.Text, 1, 1)
End Sub
Sub 甲2b()
    ActivePresentation.Slides(k).Shapes("答甲2").TextEffect.Text = Mid(ActivePresentation.Slides(k).Shapes("甲2b").TextEffect.Text, 1, 1)
End Sub

'提交
Sub 甲提交()
    Dim 分数甲 As Long
    If ActivePresentation.Slides(k).Shapes("答甲1").TextEffect.Text = "B" Then
        分数甲 = 分数甲 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答甲2").TextEffect.Text = "C" Then
        分数甲 = 分数甲 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答甲3").TextEffect.Text = "C" Then
        分数甲 = 分数甲 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答甲4").TextEffect.Text = "C" Then
        分数甲 = 分数甲 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答甲5").TextEffect.Text = "B" Then
        分数甲 = 分数甲 + 20
    End If
     ActivePresentation.Slides(k).Shapes("甲得分").TextEffect.Text = "恭喜你此次挑战获得:" & 分数甲 & "分"
End Sub
'重做

Sub 甲重做()
    ActivePresentation.Slides(k).Shapes("甲题目1").Left = 0.46 * 28.35
    ActivePresentation.Slides(k).Shapes("甲题目1").Top = -11.68 * 28.35
    ActivePresentation.Slides(k).Shapes("甲题目2").Left = 0.46 * 28.35
    ActivePresentation.Slides(k).Shapes("甲题目2").Top = -11.68 * 28.35
    ActivePresentation.Slides(k).Shapes("甲题目3").Left = 0.46 * 28.35
    ActivePresentation.Slides(k).Shapes("甲题目3").Top = -11.68 * 28.35
    ActivePresentation.Slides(k).Shapes("甲题目4").Left = 0.46 * 28.35
    ActivePresentation.Slides(k).Shapes("甲题目4").Top = -11.68 * 28.35
    ActivePresentation.Slides(k).Shapes("甲题目5").Left = 0.46 * 28.35
    ActivePresentation.Slides(k).Shapes("甲题目5").Top = -11.68 * 28.35
   
    ActivePresentation.Slides(k).Shapes("答甲1").TextEffect.Text = ""
    ActivePresentation.Slides(k).Shapes("答甲2").TextEffect.Text = ""
    ActivePresentation.Slides(k).Shapes("答甲3").TextEffect.Text = ""
    ActivePresentation.Slides(k).Shapes("答甲4").TextEffect.Text = ""
    ActivePresentation.Slides(k).Shapes("答甲5").TextEffect.Text = ""
   
    ActivePresentation.Slides(k).Shapes("甲得分").TextEffect.Text = "恭喜你此次挑战获得:"
   
End Sub
Sub 开始()
    ActivePresentation.Slides(k).Shapes("甲题目1").Top = ActivePresentation.Slides(k).Shapes("甲题目1").Top + 400
    ActivePresentation.Slides(k).Shapes("甲当前题").TextEffect.Text = 1
    ActivePresentation.Slides(k).Shapes("乙题目1").Top = ActivePresentation.Slides(k).Shapes("乙题目1").Top + 400
    ActivePresentation.Slides(k).Shapes("乙当前题").TextEffect.Text = 1
    For m = 120 To 0 Step -1
        ActivePresentation.Slides(k).Shapes("剩时").TextEffect.Text = m
        d = Timer
        暂停时间 = 1
        Do While Timer - d < 暂停时间
        DoEvents
        Loop
        Next m
    If ActivePresentation.Slides(k).Shapes("剩时").TextEffect.Text = 0 Then
    Dim 分数甲 As Long
    Dim 分数乙 As Long
    If ActivePresentation.Slides(k).Shapes("答甲1").TextEffect.Text = "B" Then
        分数甲 = 分数甲 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答甲2").TextEffect.Text = "C" Then
        分数甲 = 分数甲 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答甲3").TextEffect.Text = "C" Then
        分数甲 = 分数甲 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答甲4").TextEffect.Text = "C" Then
        分数甲 = 分数甲 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答甲5").TextEffect.Text = "B" Then
        分数甲 = 分数甲 + 20
    End If
     ActivePresentation.Slides(k).Shapes("甲得分").TextEffect.Text = "恭喜你此次挑战获得:" & 分数甲 & "分"
    End If
   
    If ActivePresentation.Slides(k).Shapes("答乙1").TextEffect.Text = "B" Then
        分数乙 = 分数乙 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答乙2").TextEffect.Text = "C" Then
        分数乙 = 分数乙 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答乙3").TextEffect.Text = "C" Then
        分数乙 = 分数乙 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答乙4").TextEffect.Text = "C" Then
        分数乙 = 分数乙 + 20
    End If
    If ActivePresentation.Slides(k).Shapes("答乙5").TextEffect.Text = "B" Then
        分数乙 = 分数乙 + 20
    End If
     ActivePresentation.Slides(k).Shapes("乙得分").TextEffect.Text = "恭喜你此次挑战获得:" & 分数乙 & "分"
   
End Sub

Sub 甲下一题()
    Dim i As Long
    If CInt(ActivePresentation.Slides(k).Shapes("甲当前题").TextEffect.Text) = 5 Then
        MsgBox "已经是最后1题了"
        Exit Sub
    End If
    i = CInt(ActivePresentation.Slides(k).Shapes("甲当前题").TextEffect.Text) + 1
    ActivePresentation.Slides(k).Shapes("甲题目" & i).Top = ActivePresentation.Slides(k).Shapes("甲题目" & i).Top + 400
    ActivePresentation.Slides(k).Shapes("甲题目" & i - 1).Top = ActivePresentation.Slides(k).Shapes("甲题目" & i - 1).Top - 400
    ActivePresentation.Slides(k).Shapes("甲当前题").TextEffect.Text = i
End Sub


Sub 乙下一题()
    Dim j As Long
    If CInt(ActivePresentation.Slides(k).Shapes("乙当前题").TextEffect.Text) = 5 Then
        MsgBox "已经是最后1题了"
        Exit Sub
    End If
   
    j = CInt(ActivePresentation.Slides(k).Shapes("乙当前题").TextEffect.Text) + 1
    ActivePresentation.Slides(k).Shapes("乙题目" & j).Top = ActivePresentation.Slides(k).Shapes("乙题目" & j).Top + 400
    ActivePresentation.Slides(k).Shapes("乙题目" & j - 1).Top = ActivePresentation.Slides(k).Shapes("乙题目" & j - 1).Top - 400
    ActivePresentation.Slides(k).Shapes("乙当前题").TextEffect.Text = j
End Sub


TA的精华主题

TA的得分主题

发表于 2023-5-19 14:31 | 显示全部楼层
ActiveWindow.Selection.SlideRange.SlideIndex是变量,变量不能赋值给常量

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-5-19 14:54 | 显示全部楼层
tanglf188 发表于 2023-5-19 14:31
ActiveWindow.Selection.SlideRange.SlideIndex是变量,变量不能赋值给常量

能否帮我改一下这个课堂交互式小游戏课件?就是那句代码,用常量虽然可以,
但下次使用加减页面就要修改k值,别人套用还得找我改,麻烦你了,谢谢!
复式统计表 .rar (1.45 MB, 下载次数: 1)

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-16 09:32 , Processed in 0.035594 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表