我是VBA的新手。
我有一长串网址(大约200个)。我想打开视频下载网站,将URL粘贴到单元格中,然后移至下一个,在新标签页(而不是新窗口)中打开它。
这是我到目前为止所拥有的:
Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
Sub OpenDownloader()
Dim ie As Object
Dim x As Integer
Dim y As Integer
Dim url As String
Dim repeat As Integer
y = 0
repeat = InputBox("How many videos to download?")
Set ie = CreateObject("Internetexplorer.Application")
apiShowWindow ie.hwnd, SW_MAXIMIZE
Do While y < repeat
x = Cells(1, "C").Value
url = Cells(x, "A").Value
Cells(x, "A").Interior.Color = RGB(198, 224, 180)
Range("C1").Select
ActiveCell.FormulaR1C1 = ActiveCell.Value + 1
If y = 0 Then
With ie
.Visible = True
.Navigate "https://qdownloader.net/"
End With
Do
DoEvents
Loop Until ie.readystate = 4
ie.Document.GetElementsByName("video")(0).Value = url
Do
DoEvents
Loop Until ie.readystate = 4
ie.Document.GetElementById("downloadBtn").Click
Do
DoEvents
Loop Until ie.readystate = 4
Else
With ie
.Visible = True
.Navigate "https://qdownloader.net/", 2048&
End With
Do
DoEvents
Loop Until ie.readystate = 4
ie.Document.GetElementsByName("video")(0).Value = url
Do
DoEvents
Loop Until ie.readystate = 4
ie.Document.GetElementById("downloadBtn").Click
Do
DoEvents
Loop Until ie.readystate = 4
End If
y = y + 1
Loop
End Sub
问题在于,当它在新选项卡中打开第一个实例之后的每个实例时,只会将链接粘贴到第一个选项卡的字段中。我一直在搜索,但是找不到解决此问题的方法。我可以打开它并在多个窗口中运行,但是为了易于使用,我宁愿在选项卡中打开它。
任何帮助将不胜感激。谢谢。