teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

(1)社内サイトからダウンロードしたExcelファイルを開く コードを追記しました。

2020/12/28 14:55

投稿

koyamashinji
koyamashinji

スコア45

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- 以下、(1)社内サイトから自動でExcelファイルを開、(2)開いたエクセルファイルを取得するコードです(動作はOK)。
1
+ 以下、(1)社内サイトからダウンロードしたExcelファイルを開、(2)開いたエクセルファイルを取得するコードです(動作はOK)。
2
2
 
3
3
 
4
4
  (★)の`DoEvents`と`Sleep 100`の部分について、
@@ -25,10 +25,33 @@
25
25
  ```VBA
26
26
 
27
27
 
28
- '(1)社内サイトから自動でExcelファイルを開く
29
28
  (省略)
30
29
 
31
30
 
31
+ '(1)社内サイトからダウンロードしたExcelファイルを開く
32
+ Dim o As IUIAutomation
33
+ Dim e As IUIAutomationElement
34
+ Set o = New CUIAutomation
35
+ Dim h As LongPtr
36
+ h = ie.hwnd
37
+ h = FindWindowEx(h, 0, "Frame Notification Bar", vbNullString)
38
+ If h = 0 Then Exit Sub
39
+
40
+ Set e = o.ElementFromHandle(ByVal h)
41
+ Dim iCnd As IUIAutomationCondition
42
+ Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "ファイルを開く")
43
+
44
+ Dim Button As IUIAutomationElement
45
+ Dim InvokePattern As IUIAutomationInvokePattern
46
+
47
+ While InvokePattern Is Nothing
48
+ DoEvents
49
+ Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
50
+ Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
51
+ Wend
52
+ InvokePattern.Invoke '『開く』ボタンを押すコード
53
+
54
+
32
55
  '(2)自動で開かれたワークブックオブジェクトを取得する
33
56
  Dim wb As Workbook
34
57
  Dim isFound As Boolean
@@ -46,7 +69,7 @@
46
69
  If isFound Then
47
70
  Exit For
48
71
  Else
49
- DoEvents
72
+ DoEvents (★)
50
73
  Sleep 100
51
74
  End If
52
75
  Next