私はこれに問題があります。
ファイルをアップロードする必要があるページがあります。[ブラウザ] をクリックすると、[アップロードするファイルを選択] ウィンドウが開き、そこで TXT ファイルを選択 (ダブルクリック) する必要があります。
Set fd = Application.FileDialog(msoFileDialogFilePicker) を使用してみましたが、このオブジェクトが認識されません。
どんな助けでも大歓迎です!
Sub Main
' Get the browser object belonging to the active/topmost IE tab
Dim objIe
Dim activeDocument
Dim Button
Set activeDocument = Nothing
' Try and get the window object of the active IE tab
Set objIe = GetActiveBrowserObj 'this is a function previously defined that allows me to work on the active browser window
If objIe Is Nothing Then
MsgBox "Could not get active IE document object”
Exit Sub
End If
' Assign the document object to the activeDocument variable
Set activeDocument = objIe.Document
If activeDocument Is Nothing Then
MsgBox "Could not get active IE document object"
Exit Sub
End If
'Click the browse button to upload the first TXT file
Set Button = objIe.Document.getElementById("txtfile1")
Button.Click
chooseFile()
End Sub
Private Sub chooseFile()
Dim fd
Dim strTxt As String
Start:
'Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Title = "Choose File to Upload" 'Change the title to suit
.Filters.Add "txt files", "*.txt", 1 'Change the filters to suit, or omit for none
.AllowMultiSelect = False
If .Show = -1 Then
'The user made a selection. The variable strWorkBook will contain the path\name of the file
strTxt = .SelectedItems(1)
Else
response = MsgBox("You have not selected a txt file")
If response = vbRetry Then
GoTo Start
Else
Exit Sub
End If
End If
End With
Set fd = Nothing
End Sub