- 題名: 起動中のExcelブック操作
 - 日時: 2009/09/03 12:40:57
 - ID: 25347
 - この記事の返信元: 
- (なし)
 
 - この記事への返信: 
- [25348] Re[1]: 起動中のExcelブック操作2009/09/03 14:27:52
 
 - ツリーを表示
 
■No25347に返信(smkさんの記事)
> 最小化されていれば「元のサイズに戻す」したいです。
これでどうでしょう。
Dim filePath As String = "C:\USER\smk\Book1.xls"
Dim o As Object = Nothing
Dim ap As Object = Nothing
Try
    o = GetObject(filePath)
    ap = CallByName(o, "Application", CallType.Get)
    Const xlNormal As Integer = -4143
    'Const xlMaximized As Integer = -4137
    'Const xlMinimized As Integer = -4140
    Dim s As String = CStr(CallByName(ap, "Caption", CallType.Get))
    AppActivate(s)
    CallByName(ap, "WindowState", CallType.Let, xlNormal)
Catch ex As Exception
    'MsgBox(ex.Message)
Finally
    If o IsNot Nothing Then
        If System.Runtime.InteropServices.Marshal.IsComObject(o) Then
            System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
        End If
        o = Nothing
    End If
    If ap IsNot Nothing Then
        If System.Runtime.InteropServices.Marshal.IsComObject(ap) Then
            System.Runtime.InteropServices.Marshal.ReleaseComObject(ap)
        End If
        ap = Nothing
    End If
End Try
分類:[.NET]
お世話になっております。
起動中のExcelブックの中から、あるExcelブックを
最前面に表示して、最小化されていれば「元のサイズに戻す」したいです。
現在以下のような手順で最前面に表示することはできているのですが、
「元のサイズに戻す」方法が分りません。
Dim prcExcels As Process() = Process.GetProcessesByName("Excel")
Dim target As String = "AAA.xls" '操作したいExcelファイル名
Dim title As String = "Microsoft Excel - " & target
For Each prcExcel As Process In prcExcels
If prcExcel.MainWindowTitle.StartsWith(title) Then
'Excel画面を最前面に表示
AppActivate(prcExcel.MainWindowTitle)
'※「元のサイズに戻す」処理を入れたい
Exit For
End If
Next
よい方法をご存じの方がいらっしゃいましたら、ご教授頂きたく存じます。
よろしくお願いいたします。