<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; Вызов функций API через Excel.ExecuteExcel4Macro]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=2055&amp;type=atom" />
	<updated>2008-08-08T10:56:52Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=2055</id>
		<entry>
			<title type="html"><![CDATA[Вызов функций API через Excel.ExecuteExcel4Macro]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=13084#p13084" />
			<content type="html"><![CDATA[<p>Пример восстанавливает все окна на Рабочем столе:<br /></p><div class="codebox"><pre><code>Const GW_HWNDPREV = 3
Const SW_RESTORE = 9

Set Excel=CreateObject(&quot;Excel.Application&quot;)
Tasks=Array()
hwnd=Excel.ExecuteExcel4Macro(&quot;CALL(&quot;&quot;user32&quot;&quot;,&quot;&quot;FindWindowA&quot;&quot;,&quot;&quot;JCC&quot;&quot;,&quot;&quot;Progman&quot;&quot;,&quot;&quot;Program Manager&quot;&quot;)&quot;)
Do
  hwnd=Excel.ExecuteExcel4Macro(&quot;CALL(&quot;&quot;user32&quot;&quot;,&quot;&quot;GetWindow&quot;&quot;,&quot;&quot;JJJ&quot;&quot;,&quot;&amp; hwnd &amp;&quot;,&quot;&amp; GW_HWNDPREV &amp;&quot;)&quot;)
  If hwnd=0 Then Exit Do
  If Excel.ExecuteExcel4Macro(&quot;CALL(&quot;&quot;user32&quot;&quot;,&quot;&quot;IsWindowVisible&quot;&quot;,&quot;&quot;JJ&quot;&quot;,&quot;&amp; hwnd &amp;&quot;)&quot;) Then
    If Excel.ExecuteExcel4Macro(&quot;CALL(&quot;&quot;user32&quot;&quot;,&quot;&quot;IsIconic&quot;&quot;,&quot;&quot;JJ&quot;&quot;,&quot;&amp; hwnd &amp;&quot;)&quot;) Then
      Push Tasks,hwnd
    End If
  End If
Loop

For Each hwnd In Tasks
  Excel.ExecuteExcel4Macro &quot;CALL(&quot;&quot;user32&quot;&quot;,&quot;&quot;ShowWindow&quot;&quot;,&quot;&quot;JJJ&quot;&quot;,&quot; &amp; hwnd &amp; &quot;,&quot;&amp; SW_RESTORE &amp;&quot;)&quot;
Next

Sub Push(Items,Item)
  ReDim Preserve Items(UBound(Items)+1)
  Items(UBound(Items))=Item
End Sub</code></pre></div><p>Пример перемещает окно с указанным заголовком (в данном случае &quot;Свойства системы&quot;, вызывается Win+Pause) на передний план:<br /></p><div class="codebox"><pre><code>Set Excel=CreateObject(&quot;Excel.Application&quot;) 
hwnd=Excel.ExecuteExcel4Macro(&quot;CALL(&quot;&quot;user32&quot;&quot;,&quot;&quot;FindWindowA&quot;&quot;,&quot;&quot;JJC&quot;&quot;,0,&quot;&quot;Свойства системы&quot;&quot;)&quot;) 
Excel.ExecuteExcel4Macro(&quot;CALL(&quot;&quot;user32&quot;&quot;,&quot;&quot;SetWindowPos&quot;&quot;,&quot;&quot;JJJJJJJJ&quot;&quot;,&quot; &amp; hwnd &amp; &quot;,-1,0,0,0,0,3)&quot;)</code></pre></div><p>Метод <strong>ExecuteExcel4Macro</strong> выполняет код Excel 4.0 и возвращает результат. Функция <strong>CALL</strong>, используемая в примерах, позволяет вызывать произвольные функции DLL. Синтаксис:<br /></p><div class="quotebox"><blockquote><p>CALL(dll_name, function_name, type_string, arg1, ..., argN)</p></blockquote></div><p><strong>dll_name</strong> - название DLL, которая содержит нужную функцию. Это название должно содержать полный путь, если файл DLL не расположен в папке Windows, Системной папке или папке, указанной в переменной среды PATH.<br /><strong>function_name</strong> - имя функции.<br /><strong>type_string</strong> - текстовая строка, определяющая тип данных возвращаемого значения и типы данных всех параметров. Первый символ type_string определяет возвращаемое значение.<br /><strong>arg1... argN</strong> - параметры функции. Их типы должны соответствовать type_string. Может быть передано до 27 параметров.</p><p>Типы данных для <strong>type_string</strong>:<br /><strong>B</strong> - 8-byte floating-point number (IEEE), Transfered by Value, C type double.<br /><strong>C</strong> - Zero (null) terminated string (max. length = 255 characters), Transfered by Reference, C type char*<br /><strong>F</strong> - Zero (null) terminated string (max. length = 255 characters), Transfered by Reference (modify in place), C type char*<br /><strong>J</strong> - 4 bytes wide signed integer, Transfered by Value, C type long int<br /><strong>P</strong> - Excel&#039;s OPER data structure, Transfered by Reference, C type OPER *<br /><strong>R</strong> - Excel&#039;s XLOPER data structure, Transfered by Reference, C type XLOPER *</p>]]></content>
			<author>
				<name><![CDATA[The gray Cardinal]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2</uri>
			</author>
			<updated>2008-08-08T10:56:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=13084#p13084</id>
		</entry>
</feed>
