vba代码中的限定符错误消息无效

时间:2018-02-12 18:21:41

标签: excel vba excel-vba

此代码用于检测形状的开始和结束列,该形状用于并显示在形状本身的标题上。以下代码是有问题的代码:

Sub Take_Baseline()
Dim forcast_weeksStart() As String
Dim forcast_weeksEnd() As String
Dim forcastDate As String
Dim shp As Shape
Dim split_text() As String




'cycle through all the shapes in the worsheet and enter the forcast date for all the projects into their respective boxes



For Each shp In ActiveSheet.Shapes

          'initialize forcast date by parsing
    forcast_weeksStart = Split(shp.TopLeftCell.Column.Text, " ")
    forcast_weeksEnd = Split(shp.BottomRightCell.Column.Text, " ")
    forcastDate = forcast_weeksStart(1) & "-" & forcast_weeksEnd(1)


        temp = shp.OLEFormat.Object.Object.Caption
        If InStr(temp, "/-/") > 0 & InStr(temp, "In Prog") Then
            split_text = Split(shp.OLEFormat.Object.Caption, " ")
            For i = 0 To (i = 3)
                            shp.TextFrame.Characters.Caption = split_text(i) & vbNewLine
                        Next i
                        ActiveSheet.Shapes(Sheet4.Range("B1")).TextFrame.Characters.Caption = ActiveSheet.Shapes(Sheet4.Range("B1")).TextFrame.Characters.Caption & vbNewLine & ActiveSheet.Cells(4, AShape.TopLeftCell.Column).Text & " - " & ActiveSheet.Cells(4, AShape.BottomRightCell.Column).Text & vbNewLine & "dates: " & forcast_weeksStart(1) & " - " & forcast_weeksEnd(1) & "/" & forcast_weeksStart(1) & " - " & forcast_weeksEnd(1) & "/" & "/" & "actualDate"
       ' ElseIf InStr(temp, "/-/") > 0 & InStr(temp, "In Prog") = 0 Then
             'split_text = Split(shp.OLEFormat.Object.Object.Caption, " ")
           ' For i = 0 To (i = 2)
                           ' shp.OLEFormat.Object.Caption = split_text(i) & vbNewLine
                       ' Next i
                        'ActiveSheet.Shapes(Sheet4.Range("B1")).TextFrame.Characters.Caption = ActiveSheet.Shapes(Sheet4.Range("B1")).TextFrame.Characters.Caption & vbNewLine & "In Prog" & vbNewLine & ActiveSheet.Cells(4, AShape.TopLeftCell.Column).Text & " - " & ActiveSheet.Cells(4, AShape.BottomRightCell.Column).Text & vbNewLine & "dates: " & forcast_weeksStart(1) & " - " & forcast_weeksEnd(1) & "/" & forcast_weeksStart(1) & " - " & forcast_weeksEnd(1) & "/" & "actualDate"
        End If
    Next shp


    'For testing purposes

    Sheet4.Range("A20").Value = forcast_weeksStart(1)
    Sheet4.Range("A21").Value = forcast_weeksEnd(1) End Sub

错误是

  

“无效限定符”

消息发生在线

forcast_weeksStart = Split(shp.TopLeftCell.Column.Text, " ")

正确的“专栏”字样。我不明白为什么会发生这种情况,因为实际的下拉菜单有我可以选择的列操作。我已经尝试了从更改它到OLEformat.Object.Caption等所有的一切。但没有任何工作。我还是比较新的vba所以任何帮助将不胜感激。感谢

0 个答案:

没有答案