[[20191025121409]] 『Excel2003で作ったマクロをExcel2007で動作させた』(もぐら) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『Excel2003で作ったマクロをExcel2007で動作させたい』(もぐら)

OSがWindowsXPでExcel2003の時に動作していたマクロをWindows7のExcel2007の環境で動作させたいのですが「Error429,ActiveXコンポーネントはオブジェクトを作成できません」と表示され正常に動作しません。
何か対策方法はあるのでしょうか?初心者なので噛み砕いて説明してもらえると助かります。よろしくお願いします。

< 使用 Excel:Excel2007、使用 OS:Windows7 >


初心者かどうかなんて関係なく、まずはどんなマクロなのか見せてもらわないと何とも…。
(???) 2019/10/25(金) 13:02

こんなのです。
Private Sub CommandButtonStart_Click()

    On Error GoTo CommandButtonStartErr
    ToolbarCode.DebugPos = 10

    Dim ws As Worksheet
    Dim i As Long
    Dim blnCellOK As Boolean
    Dim ret As Boolean
    Dim intSelCount As Integer

    If False <> ToolbarCode.FastAcqOn Then Exit Sub
    If ((True = IsRealtime()) And (UCase(lstDP.List(0)) = "NONE")) Then
        ToolbarCode.DebugPos = 20
        Call ResetStart
        MsgBox "Turn on a source at the scope", vbOKOnly, AppName
        Exit Sub
    End If
    ToolbarCode.DebugPos = 30
    If UCase(lstMeas.List(0)) = "NONE" Then
        ToolbarCode.DebugPos = 40
        Call ResetStart
        MsgBox "Turn on a measurement at the scope", vbOKOnly, AppName
        Exit Sub
    End If
    intSelCount = 0
    For i = 0 To (Me.lstMeas.ListCount - 1)
        If lstMeas.Selected(i) Then intSelCount = intSelCount + 1
    Next
    If 0 >= intSelCount Then
        MsgBox "No measurement selected.", vbOKOnly, AppName
        Exit Sub
    End If
    If (True = IsRealtime()) Then
        intSelCount = 0
        For i = 0 To (Me.lstDP.ListCount - 1)
            If lstDP.Selected(i) Then intSelCount = intSelCount + 1
        Next
        If 0 >= intSelCount Then
            MsgBox "No channel selected.", vbOKOnly, AppName
            Exit Sub
        End If
    End If
    ToolbarCode.DebugPos = 50
    If fDelayed Then
        If WaitTillStartTime = False Then
            ToolbarCode.DebugPos = 60
            Exit Sub
        End If
    End If

    ToolbarCode.DebugPos = 70
' check that we have a worksheet to paste data into
    ret = CheckSheets
    If ret = False Then Exit Sub

    ToolbarCode.DebugPos = 80
    blnCellOK = CheckCell(frmMeasurement.txtCell.Text, frmMeasurement.txtCell, frmMeasurement.txtRow, _
                        frmMeasurement.txtCol, frmMeasurement.spnRow, frmMeasurement.spnCol)
    If blnCellOK = False Then
        ToolbarCode.DebugPos = 90
        Call ResetStart
        Exit Sub
    End If
    ToolbarCode.DebugPos = 100
    Range(frmMeasurement.txtCell.Text).Activate
' check the record length > 0
    If lngRecLength = 0 Then
        ToolbarCode.DebugPos = 110
        Call ResetStart
        Exit Sub
    End If

    ToolbarCode.DebugPos = 120
' create the ActiveX component for handling timer events
    If tmrGM Is Nothing Then
        ToolbarCode.DebugPos = 130
        Set tmrGM = CreateObject("p_TimedMeas.clsTimedMeas")
    End If

    ToolbarCode.DebugPos = 140
    If (True = IsRealtime()) Then
' clear the array of selected boolean values
        ToolbarCode.DebugPos = 150
        For i = LBound(arrmeas) To UBound(arrmeas)
            ToolbarCode.DebugPos = 160
            arrmeas(i).blnSelected = False
            arrmeas(i).rValue = 0
        Next
    End If

    ToolbarCode.DebugPos = 170
'activesheet or new sheet
    If optNewsheet.Value = True Then
        ToolbarCode.DebugPos = 180
        Set ws = Application.Worksheets.Add(After:=Application.Worksheets(Application.Worksheets.Count))
    Else
        ToolbarCode.DebugPos = 190
        Set ws = Application.ActiveSheet
    End If

    If optSingle.Value = True Then
' code for single measurement
        DebugPos = 200
        lStartRow = spnRow.Value
        lStartCol = spnCol.Value
        nLCount = lstMeas.ListCount

        ToolbarCode.DebugPos = 210
        If (True = IsRealtime()) Then
            ToolbarCode.DebugPos = 220
            ret = BuildCMDString
            If ret = False Then
                ToolbarCode.DebugPos = 230
                Call ResetStart
                Exit Sub
            End If
            ToolbarCode.DebugPos = 240
            Call GetSingleMeasurement(ws)
        Else
            ToolbarCode.DebugPos = 250
            Call BuildCMDString8000(frmMeasurement.lstMeas)
            ToolbarCode.DebugPos = 260
            Call GetSingleMeasurement8K(ws)
        End If
        ToolbarCode.DebugPos = 270
        CommandButtonStart.Visible = True
        CommandButtonStop.Visible = False
        CommandButtonWaiting.Visible = False
    Else    'make repeated measurements
        ToolbarCode.DebugPos = 280
        lStartRow = spnRow.Value
        lStartCol = spnCol.Value
        nLCount = lstMeas.ListCount
        ToolbarCode.DebugPos = 290
        If (True = IsSampling()) Then
            ToolbarCode.DebugPos = 300
            Call BuildCMDString8000(frmMeasurement.lstMeas)
        Else  ' this is a 5k/7k scope
            ToolbarCode.DebugPos = 310
            ret = BuildCMDString
            If ret = False Then
                ToolbarCode.DebugPos = 320
                Call ResetStart
                Exit Sub  'the resetstart will reenable the row/col opt.
            End If
        End If

        If lstMeas.List(0) = "NONE" Then
            Exit Sub
        End If

        ToolbarCode.DebugPos = 330
        If xlInsert Is Nothing Then Set xlInsert = CreateObject("p_ExcelInsert.CExcelInsert")

'routine sets up the ActiveX exe; large # of parameters due to cross-process marshalling

        ToolbarCode.DebugPos = 340
        Call xlInsert.Configure(ws, lStartRow, lStartCol, blnDisplayColumns, sCharting, sChartPos)
        ToolbarCode.DebugPos = 350

        TimerMode = "GET_MEASUREMENT"
        ToolbarCode.DebugPos = 360
        With tmrGM
            ToolbarCode.DebugPos = 370
            Set .xlInsert = xlInsert            ' pass reference of xlInsert to tmrGM component
            ToolbarCode.DebugPos = 380
            Set ToolbarCode.tvcRef = frmHoldTVC.Tvc1
            Set .MTVCRef = ToolbarCode.tvcRef            ' pass reference of TVC control to tmrGM component
            ToolbarCode.DebugPos = 390
            Set .MeasForm = frmMeasurement      ' pass reference of frmMeasurement to tmrGM component
            ToolbarCode.DebugPos = 400
            .TimerInterval = tInterval * 1000   ' timer interval
            ToolbarCode.DebugPos = 410
            .strCMD = strCMD                    ' command string
            ToolbarCode.DebugPos = 420
            .Tracker = 0                        ' tracking variable
            ToolbarCode.DebugPos = 430
            .reclength = lngRecLength           ' number of measurement captures
            ToolbarCode.DebugPos = 440
            .ChartingType = sCharting           ' COMPLETION, PERIODIC or NONE

            If sCharting = "PERIODIC" Then
                ToolbarCode.DebugPos = 450
                .blnFirstUpdate = True
                ToolbarCode.DebugPos = 460
                .ChartUpdateInterval = nChartUpdate   ' for periodic chart updating
            Else
                ToolbarCode.DebugPos = 470
                .ChartUpdateInterval = 0
            End If
        End With
        lblTotalDP.Visible = True
        lblTotalDP.Caption = lngRecLength
        lblCurrentNum.Visible = True
        lblCurrentNum.Caption = "0 of:"
        CommandButtonStart.Visible = False
        CommandButtonStop.Visible = True
        CommandButtonWaiting.Visible = False
        ToolbarCode.DebugPos = 480
        tmrGM.EnableTimer = True   ' start the timer
    End If
    Exit Sub

CommandButtonStartErr:

    MsgBox "Error: " & Err.Number & ", " & Err.Description, vbOKOnly, AppName
    ToolbarCode.LogError "frmMeasurement|cmdStartStart", Err.Number, Err.Description
End Sub
(もぐら) 2019/10/25(金) 13:29

 このコード以外に ToolbarCode っていう オブジェクトを生成するコードがあって
 それが、生成されてない(できない)というエラーではないかと思います。

 VBA標準ではないので、Excel2003のPCにはライブラリまたはDLLがインストールされていたのではないですか?

 自前のクラスからのオブジェクトでもないようですが、測定器か何かについてきたマクロで
 別なPCで使用するためには、きちんとインストール作業を行わないといけないのでは?
 その際にはライセンスも確認してくださいね

 Win7に対応しているかどうかも怪しいですが・・・

 
(渡辺ひかる) 2019/10/25(金) 14:37


ToolbarCodeを確認しましたが、詳しく理解出来ませんが恐らくおっしゃる通りな気がします。
確かにこれは測定器用のマクロです。メーカーサイトから無料配布されていたようなのでライセンスは大丈夫です。
参照設定を確認すると同じライブラリを使用していました。ということはdllが足りないのでしょうか?メーカーに問い合わせたらWin7は対応していないので動くかどうかはわからないと言われたのですが仕事で必要なためどうにか動かないか思考錯誤のすえ質問させていただきました。

渡辺ひかるさんの回答に納得したので諦める事にします。ありがとうございました。
(もぐら) 2019/10/25(金) 16:01


 以下の物が使えないだろうか?
 Windows7上で仮想PCをWindowsXPで動かしその中でEXCEL及びメーカからの提供物を実行することになる。
 ただし通常の使用とは異なるためこれで実行できるかは不明。

https://www.microsoft.com/ja-jp/download/details.aspx?id=3702
https://www.microsoft.com/ja-jp/download/details.aspx?id=8002

(ねむねむ) 2019/10/25(金) 16:18


 >参照設定を確認すると同じライブラリを使用していました

 参照不可にはなっていませんでしたか?

(渡辺ひかる) 2019/10/25(金) 16:52


>ねむねむさん
試してみましたがダメでした。

>渡辺ひかるさん
参照不可にはなっていませんでした。
(もぐら) 2019/10/28(月) 13:30


独自コントロール利用となると、回答者側ではデバッグ実行することができないので、ご自身で調べるしかありません。 On Error GoTo文はコメントアウトしてからステップ実行し、どの行でエラーになるのか特定してみてください。

Excel2003と2007では大きく構造が変化(ブック形式がZIP圧縮されたXMLファイルに変わった)しており、命令が変わったものもあるので、バージョン違いが疑わしいのですが、それらしい命令は使っていないようなのです。 そうなると、使用しているコントロールが現状のWIN7で何か問題があるのかも知れません。 64bitのWIN7だったりはしませんか?(でも参照設定で不可になっていないのだから、32bitなんでしょうねぇ)

あとは、メーカーに問い合わせる事はできませんか? 環境構築できない我々に聞くより、作成元の方が確実な答えを得られると思います。
(???) 2019/10/28(月) 14:05


 >参照不可にはなっていませんでした。

 そうなんですか・・

 では、「参照」はできているんですね。

 手元にあれば、

 オブジェクトブラウザで見てみるとか
 インテリセンスが利くかどうかとか

 調べてみたいところはいろいろあるんですけどね・・・

(渡辺ひかる) 2019/10/28(月) 16:17


コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.