ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 9147|回复: 14

FAQ 【网络应用】

[复制链接]

TA的精华主题

TA的得分主题

发表于 2004-11-24 11:01 | 显示全部楼层 |阅读模式

VBA可否检测出IP地址和工作组名称?

请参考【测出IP地址和工作组名称】

请参考【Get IP address】

如何在VBA中检查网络有无可用的Internet连接

请参考【如何在VBA中检查网络有无可用的Internet连接】

如何从网页插入指定图片在 WorkSheet 内

Cells(3, 3).Select ActiveSheet.Pictures.Insert "http://club.excelhome.net/UploadFile/2004-9/2004917204418292.jpg"

如何用VBA控制 IE

请参考【如何用VBA控制IE】4/F; 8/F

[此贴子已经被作者于2005-5-7 11:53:36编辑过]

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-7-23 18:12 | 显示全部楼层

Window 版本主編號 (2)

' By chijanzen

Private Declare Function GetVersionExA Lib "kernel32" _
(lpVersionInformation As OSVERSIONINFO) As Long

Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long      ' 此一資料結構的大小
dwMajorVersion As Long          ' 版本主編號, 例如 4.0.950 的 4
dwMinorVersion As Long          ' 版本次編號, 例如 4.0.950 的 0
dwBuildNumber As Long           ' 版本建立編號, 例如 4.0.950 的 950
dwPlatformId As Long            ' 作業平臺
szCSDVersion As String * 128    ' 版本的進一步說明
End Type
Public lpVersionInformation As OSVERSIONINFO
'VER_PLATFORM_WIN32s(= 0) Win32s, 可在 Win 3.1 底下執行 32 位元元應用程式的平臺
'VER_PLATFORM_WIN32_Windows(= 1)  Windows 95 或 98
'VER_PLATFORM_WIN32_NT(= 2)  Windows NT 或 200 或 XP


Sub ShowWVersion()
Dim s As String, a As String
a = OperatingSystem
Select Case a
Case 0: s = "Windows 32"
Case 1: s = "Windows 95"
Case 2: s = "Windows 98"
Case 3: s = "Windows ME"
Case 4: s = "Windows NT"
Case 5: s = "Windows 2000"
Case 6: s = "Windows XP"
End Select
MsgBox s
End Sub

Sub test()
MsgBox Application.OperatingSystem
End Sub

Public Function OperatingSystem() As Integer
lpVersionInformation.dwOSVersionInfoSize = Len(lpVersionInformation)
Call GetVersionExA(lpVersionInformation)
If (lpVersionInformation.dwPlatformId = 0) Then 'VER_PLATFORM_WIN32s(= 0) Win32s _
,可在 Win 3.1 底下執行 32 位元元應用程式的平臺
OperatingSystem = 0
    
ElseIf (lpVersionInformation.dwPlatformId = 1) And _
(lpVersionInformation.dwMinorVersion = 0) Then   'Win95:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion = 0
OperatingSystem = 1
    
ElseIf (lpVersionInformation.dwPlatformId = 1) And _
(lpVersionInformation.dwMinorVersion = 10) Then   'Win98:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion = 10
OperatingSystem = 2
    
ElseIf (lpVersionInformation.dwPlatformId = 1) And _
(lpVersionInformation.dwMinorVersion = 90) Then   'WinMe:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion = 90
OperatingSystem = 3
    
ElseIf (lpVersionInformation.dwPlatformId = 2) And _
(lpVersionInformation.dwMajorVersion < 5) Then    'WinNT:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion < 5
OperatingSystem = 4
    
ElseIf (lpVersionInformation.dwPlatformId = 2) And _
(lpVersionInformation.dwMajorVersion = 5) And _
(lpVersionInformation.dwMinorVersion = 0) Then    'Win2000:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion=5 and dwMinorVersion = 0
OperatingSystem = 5
    
ElseIf (lpVersionInformation.dwPlatformId = 2) And _
(lpVersionInformation.dwMajorVersion = 5) And _
(lpVersionInformation.dwMinorVersion = 1) Then    'WinXP:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion=5 and dwMinorVersion = 0
OperatingSystem = 6
    
End If
End Function


[此贴子已经被作者于2006-9-23 19:14:10编辑过]

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-7-10 12:36 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

Window 版本主編號 (1)

Option Explicit

'///////////
'//  IFM  //
'///////////

'// My thanks to "venky_dude"
'// Code modified for XP+ 26 may 2002 by Ivan F Moala
'// Errors in Type declaration on
'// platforms that don't support
'// wServicePackMajor As Integer 'NB some Platforms returns 0 and Not 1
'// wServicePackMinor As Integer 'NB some Platforms returns 0 and Not 1
'// wSuiteMask As Integer        'NB some Platforms returns 0 and Not 1
'// wProductType As Byte         'NB some Platforms returns 0 and Not 1
'// wReserved As Byte            'NB some Platforms returns 0 and Not 1
'// Testing done by MVP Members

Private Declare Function GetVersionEx _
    Lib "kernel32" _
    Alias "GetVersionExA" ( _
    lpVersionInformation As OSVERSIONINFO) _
As Long

Private Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion      As Long
    dwMinorVersion      As Long
    dwBuildNumber       As Long
    dwPlatformId        As Long
    szCSDVersion        As String * 128
End Type

Sub Tester()
MsgBox OS_Version
End Sub

Function OS_Version() As String
Dim Os As OSVERSIONINFO
Dim m As Long
Dim MjV As Long
Dim PId As Long
Dim MnV As Long

Os.dwOSVersionInfoSize = Len(Os)

m = GetVersionEx(Os)
MjV = Os.dwMajorVersion
PId = Os.dwPlatformId

MnV = Os.dwMinorVersion

If PId = 2 Then
    '// NT,2000,XP
    Select Case Os.dwMajorVersion
    Case Is = 3
        OS_Version = " Windows NT 3." & Os.dwMinorVersion
    Case Is = 4
        OS_Version = " Windows NT 4 "
    Case Is = 5
        Select Case Os.dwMinorVersion
            '// win 2000
            Case Is = 0
                OS_Version = " Windows Windows 2000 "
            '// win XP or win .NET server
            Case Is = 1
                OS_Version = " Windows XP "
            Case Else
                OS_Version = " Windows .NET Server "
        End Select
    End Select
End If

If PId = 1 Then
    If MnV = 10 Then OS_Version = " Windows 98 "
    If MnV = 0 Then OS_Version = " Windows 95 "
    If MnV = 90 Then OS_Version = " Windows ME "
End If

End Function


[此贴子已经被作者于2006-10-3 12:50:24编辑过]

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-5-7 11:50 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

OutLook

GAL - Gobal Address List by David Brett Tb44QSuq.zip (13.2 KB, 下载次数: 103)

[em17]

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-1-6 00:33 | 显示全部楼层

网域 , 计算机名称 , 使用者姓名

'设定引用项目 Windows Script Host Object Model

Dim myWshNw  As IWshRuntimeLibrary.WshNetwork
Dim myStr As String
Set myWshNw = CreateObject("Wscript.Network")
myStr = myStr & "网域 = " & myWshNw.UserDomain & vbCrLf
myStr = myStr & "计算机名称 = " & myWshNw.ComputerName & vbCrLf
myStr = myStr & "使用者姓名 = " & myWshNw.UserName & vbCrLf
MsgBox myStr
Set myWshNw = Nothing

[此贴子已经被作者于2006-9-23 19:15:11编辑过]

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-1-6 00:30 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

用Excel开启指定的IE网址

'设定引用项目 Microsoft Internet Controls On Error Resume Next Set IE = New InternetExplorer IE.Navigate URL:="http://club.excelhome.net/index.asp" IE.Visible = True

Or

Dim Newsite As Object Set Newsite = CreateObject("InternetExplorer.application") Newsite.Visible = True Newsite.Navigate "http://club.excelhome.net/index.asp"

[此贴子已经被作者于2005-3-25 23:59:06编辑过]

TA的精华主题

TA的得分主题

发表于 2005-9-7 10:59 | 显示全部楼层
以下是引用Emily在2005-1-6 0:33:00的发言: '设定引用项目 Windows Script Host Object Model

Dim myWshNw As IWshRuntimeLibrary.WshNetwork Dim myStr As String Set myWshNw = CreateObject("Wscript.Network") myStr = myStr & "网域 = " & myWshNw.UserDomain & vbCrLf myStr = myStr & "计算机名称 = " & myWshNw.ComputerName & vbCrLf myStr = myStr & "使用者姓名 = " & myWshNw.UserName & vbCrLf MsgBox myStr Set myWshNw = Nothing

Dim myWshNw As IWshRuntimeLibrary.WshNetwork

用户定义类型未定义

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-9-23 19:13 | 显示全部楼层

[分享]列出 IE 连接中 URL 清单

Method 1:

需引用 Microsoft Internet Control, Microsoft Shell Controls and Autom

Sub ListShellWindows()
' Written by Herilane orginally post in Xtreme
' Get all currently open IE and Explorer windows (those are based on the same class).
' For IE windows, get location. For WE windows, get path.
' Reference to Microsoft Internet Controls and to Microsoft Shell Controls and Automation

    Dim objShell As Shell
    Dim objIE As InternetExplorer
    Dim objExplorer As ShellFolderView
    Dim obj As Object
    Dim x As Integer

    x = 1
    Set objShell = New Shell
    For Each obj In objShell.Windows
        If TypeName(obj.Document) = "HTMLDocument" Then
            Set objIE = obj
            'Debug.Print objIE.LocationURL
            Cells(x, 1).Value = objIE.LocationURL
            x = x + 1
        Else
            Set objExplorer = obj.Document
            'Debug.Print objExplorer.FocusedItem.Path
            MsgBox objExplorer.FocusedItem.Path
        End If
    Next obj

End Sub

'

Method 2:

需引用 Microsoft Internet Controls

Sub IE_URL2()

Dim dWinFolder As New ShellWindows
Dim objIE As Object
Dim objDoc As Object

x = 1
For Each objIE In dWinFolder
Set Doc = objIE.Document
If TypeName(Doc) = "HTMLDocument" Then
    Cells(x, 1) = objIE.LocationURL
    x = x + 1
End If
Next
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-9-22 18:49 | 显示全部楼层

[分享] 代碼登陸網站 2

有些網站不僅要 UserName 及 Password ,還有特別要求。以下代碼嘗試登陸 OFFICE精英俱部。代碼是 crdotlin 編寫,我修改小小。(有驗證不適用, eg ExcelHome )

Option Explicit
Dim myIE As InternetExplorer
Dim myIEdoc As HTMLDocument
Dim theForm As HTMLFormElement
 
Sub OpenWebpageAndLogin(URL As String, myPW As String, myID As String, _
    Optional myAns As StringOptional selItem As Integer)
Dim theItm As HTMLFormElement
Dim i As Integer
Dim Testing As Variant
Dim flg As Boolean
Set myIE = New InternetExplorer
With myIE
    .Navigate URL
    .Visible = True
    Do While .Busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop
End With
Set myIEdoc = myIE.Document
Set theForm = findFm(myIEdoc, "password")
With theForm
    For i = 0 To .Length - 1
    Testing = .Item(i).Name
        Select Case .Item(i).Name
            Case "password"
                .Item(i).Value = myPW
                flg = True
            Case "username"
                .Item(i).Value = myID
            Case "answer"
                .Item(i).Value = myAns
            Case "questionid"
                .Item(i).Value = selItem    'the quation's number
            Case Else
        End Select
    Next
End With
If flg Then
    Set theForm = findFm(myIEdoc, "submit")
Else
    myIE.Quit
    MsgBox ("Unexpected Error, I'm quitting.")
End If
Set myIE = Nothing
End Sub
 
 
Function findFm(theDoc As HTMLDocument, theType As StringAs HTMLFormElement
    Dim i As Integer, j As Integer
    Dim theItm As HTMLFormElement
    With theDoc.forms
        For i = 0 To .Length - 1
            Set theItm = .Item(i)
            With theItm
                For j = 0 To .Length - 1
                    If .Item(j).Type = theType Then
                        Set findFm = theItm
                        If theType = "submit" Then .Item(j).Click
                        Exit Function
                    End If
                Next
            End With
        Next
    End With
End Function
 
Sub Test()
   OpenWebpageAndLogin URL:="http://www.officefans.net/cdb/logging.php?action=login", _
    myPW:="xxxxxx", myID:="Emily", myAns:="xxxx", selItem:=7
End Sub
'
直接下載  (另附自動新增引用項目)

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-9-22 18:47 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

[分享]代碼登陸網站

以下介紹一段登陸網站的代碼,此代碼嘗試找出 登陸 HTML Form 內的 UserName 及 Password 位置然後自動填入。

'
' Set reference to Microsoft HTML Object Library
' Set Reference to Microsoft Internet Controls
'
 
Option Explicit
 
Dim myIE As InternetExplorer
Dim myIEdoc As HTMLDocument
Dim theForm As HTMLFormElement
 
Sub OpenWebpageAndLogin(URL As String, myPW As String, myID As String)
Dim theItm As HTMLFormElement
Dim i As Integer
Dim flg As Boolean
Set myIE = New InternetExplorer
With myIE
    .Navigate URL
    .Visible = True
    Do While .Busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop
End With
Set myIEdoc = myIE.Document
Set theForm = findFm(myIEdoc)
With theForm
    For i = 0 To .Length - 1
        Select Case .Item(i).Type
            Case "password"
                .Item(i).Value = myPW
                flg = True
            Case "text"
                .Item(i).Value = myID
            Case Else
        End Select
    Next
End With
If flg Then
    theForm.submit
Else
    myIE.Quit
    MsgBox ("Unexpected Error, I'm quitting.")
End If
Set myIE = Nothing
End Sub
 
Function findFm(theDoc As HTMLDocument) As HTMLFormElement
    Dim i As Integer, j As Integer
    Dim theItm As HTMLFormElement
    With theDoc.forms
        For i = 0 To .Length - 1
            Set theItm = .Item(i)
            With theItm
                For j = 0 To .Length - 1
                    If .Item(j).Type = "password" Then
                        Set findFm = theItm
                        Exit Function
                    End If
                Next
            End With
        Next
    End With
End Function
 
Sub Test()
  OpenWebpageAndLogin "http://mysinablog.com/admin.php", "Password", "UserName"
End Sub
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-22 16:45 , Processed in 0.051730 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表