提前感谢您的回答。
我有一个小的Excel文档,以便天真的用户可以在Excel工作表中输入网页,点击按钮,在浏览器中以全屏模式播放该页面中的视频,并自动循环播放视频而不再进一步用户互动。它基本上创建了一个视频幻灯片。
我最初是为YouTube制作的,它在那里工作得很好。我现在正在尝试将其扩展为使用其他网站。它按计划工作,但需要额外的步骤。
虽然YouTube是以全屏模式制作的,我可以通过编程方式访问,但该网站已嵌入视频。 (例如:qazxsw poi)。
您可以在代码中看到我以全屏模式打开IE(它确实如此),但这是完整的网页(标题,侧边栏等)。我希望该页面的视频是唯一的元素,全屏。
如果我实际进入页面,我可以选择让视频全屏播放。我已经尝试过各种方法来搜索,但大多数帖子都是针对其他内容或者如何在Excel内部播放视频而不是我正在做的事情。
https://www.sharecare.com/video/health-topics-a-z/copd/what-can-i-do-to-prevent-my-copd-from-getting-worse
我复制了代码。它工作正常。这就是我需要的额外一点“哦,我做到了,这就是如何去做”。
使用的浏览器是IE,所以我可以保持简单,但如果这是可能的另一个常见的浏览器,这将是很好的知道。
这是我今天尝试的第二套(9/12)
Sub StartLooping()
Dim IEapp As Object
Dim VidAddr1, VidAddr2 As String
Dim AddrStrStart, AddrStrEnd As Long
Dim AddrFudge1, AddrFudge2 As Integer
Dim TimeStart, DurMin, DurSec, DurTot As Single
Dim LRAll, LRVid, LRMin, LRSec, LRVidB, LRMinB, LRSecB As Integer
Dim I As Integer
Application.EnableCancelKey = xlErrorHandler
On Error GoTo ErrorHandle
'Review Sheet
LRVid = Cells(Rows.Count, "D").End(xlUp).Row
LRMin = Cells(Rows.Count, "E").End(xlUp).Row
LRSec = Cells(Rows.Count, "F").End(xlUp).Row
LRVidB = Cells(Rows.Count, "I").End(xlUp).Row
LRMinB = Cells(Rows.Count, "J").End(xlUp).Row
LRSecB = Cells(Rows.Count, "K").End(xlUp).Row
LRAll = Cells(Rows.Count, "S").End(xlUp).Row
If LRVid <> LRMin Then
MsgBox "You have to include video address and how long (the minutes and the seconds - use 0 if needed)"
Exit Sub
End If
If LRVid <> LRSec Then
MsgBox "You have to include video address and how long (the minutes and the seconds - use 0 if needed)"
Exit Sub
End If
If LRVidB <> LRMinB Then
MsgBox "You have to include video address and how long (the minutes and the seconds - use 0 if needed)"
Exit Sub
End If
If LRVidB <> LRSecB Then
MsgBox "You have to include video address and how long (the minutes and the seconds - use 0 if needed)"
Exit Sub
End If
'Start of For-Next Loop
For I = 20 To LRAll
'Set Addr
'VidAddr1
If Len(Range("S" & I).Text) = 0 Then
Exit Sub
Else
VidAddr1 = Range("S" & I).Text
End If
VidAddr2 = VidAddr1
'Set Timer
TimeStart = Timer 'Start time
DurMin = Range("T" & I).Value
DurSec = Range("U" & I).Value
DurTot = (DurMin * 60) + DurSec
'Open the web page
Set IEapp = CreateObject("Internetexplorer.Application") 'Set IEapp = InternetExplorer
With IEapp
.Silent = True 'No Pop-ups
.Visible = True
.FullScreen = True
.Navigate VidAddr2 'Load web page
'Keep it open for the duration
Do While Timer < (TimeStart + DurTot)
'Check for Esc - refers to a public function
If KeyDown(vbKeyEscape) Then
IEapp.Quit
Set IEapp = Nothing
Exit Sub
End If
Loop
'Close the page
IEapp.Quit
Set IEapp = Nothing
End With
If I = LRAll Then I = 19
Next I
ErrorHandle:
MsgBox Err.Number & " " & Err.Description
Exit Sub
End Sub
我的建议是,使用视频播放器,而不是使用浏览器播放视频。
在“更多控制”下,您应该拥有“Windows Media Player”,可能还有其他人,具体取决于您安装的内容。
Dim IEapp As Object
Dim IEAppColl As HTMLButtonElement
'Open doc
Set IEapp = CreateObject("Internetexplorer.Application") 'Set IEapp = InternetExplorer
With IEapp
.Silent = True 'No Pop-ups
.Visible = True
'.FullScreen = True
.navigate "https://www.sharecare.com/video/health-topics-a-z/copd/got-copd-ask-your-doctor-about-vitamin-d"
Do While .readyState < 4 Or .Busy
Loop
Set IEAppColl = IEapp.Document.getElementsByTagName("BUTTON")
If IEAppColl.Name = "Fullscreen" Then
IEAppColl.Click
End If
End With
例如,我在Access表单上使用了控件。当您安装VLC时,它会自动将控件添加到Office(因此我假设必须先安装Office。)
这是我在网上找到的教程:
How to Play Video on Access Form
*YouTube*
和site:
运营商排除特定网站的搜索结果,例如:
-
...这就是我找到上面教程的方法,以及其他几个。"microsoft access" form play youtube video -site:youtube.com
也可能很难搜索,因为它是如此常见的单词,这就是为什么我经常将它括在引号中,如“MS Access”或“Microsoft Access”(如上所述),这使得Google搜索这个词按顺序排列。
access
对于给出的示例COPD页面,这适用于Selenium basic。你从(More Google tips)安装,然后去here并添加对VBE > Tools > References >
的引用。您还可以使用Selenium Type Library
与InternetExplorer而不是Chrome(使用IEDriver
)一起使用。
ChromeDriver