使用VBS实现批量修改
由于权限的原因,部分客户需要在SharePoint站点上将状态Reject,由于生产环境没有数据库权限,所以只能写个VBS来跑,代码如下:
1 OptionExplicit'强制声明
2
3 ' --------------------------------------------------------------------
4 ' Define
5 ' --------------------------------------------------------------------
6 Const DELAY_TIME = 200
7 Dim emailAddress, customerID
8 emailAddress = "meiweijun@163.com"
9 customerID = "N/A"
10 Call Main() '调用主函数
11
12 Private Sub Main()
13 Dim oIE 'As InternetExplorer.Application
14 Set oIE=CreateObject("InternetExplorer.Application")
15 oIE.Visible=True
16
17 Dim objWshShell '读取桌面文件夹
18 Set objWshShell = WScript.CreateObject("WScript.Shell")
19
20
21 ' read command line arguments
22 If WScript.Arguments.Count > 0 Then
23 emailAddress = WScript.Arguments.Item(0)
24 End If
25
26 '打开一个新的IE窗口
27 call NavigateWait(oIE,"about:blank")
28 objWshShell.AppActivate "about:blank"
29 WScript.Sleep(500)
30 call NavigateWait(oIE,"http://网址")
31 '输入Email地址并按下查询按钮
32 Dim oForm,dropdown1,inputbox1,button1
33 '获取表单
34 Set oForm=oIE.document.forms("aspnetForm")
35 '获取邮件下拉列表条件
36 set dropdown1=oIE.document.getElementsByName("ctl00$m$g_36d820b1_1932_42e6_b8a5_32d21fea0dab$ctl12")
37 '获取邮件文本框
38 Set inputbox1=oIE.document.getElementsByName("ctl00$m$g_36d820b1_1932_42e6_b8a5_32d21fea0dab$ctl13")
39 '获取查询按钮
40 Set button1 = oIE.document.getElementsByName("ctl00$m$g_36d820b1_1932_42e6_b8a5_32d21fea0dab$ctl74")
41 On Error Resume Next
42 dropdown1(0).selectedIndex=2 'email equals
43 if Err.Number>0 then
44 Call oIE.Quit()
45 Set oIE = Nothing
46 end If
47 inputbox1(0).value=emailAddress
48 button1(0).Click
49 WaitForNavigateComplete(oIE)
50
51 '到第二个页面
52 Set oForm = oIE.document.forms("aspnetForm")
53 Set button1 = oIE.document.getElementsByName("ctl00$m$g_4fdccc80_8665_4043_8b2d_264d342d4967$ctl01$ctl03$ctl00")
54 button1(0).Click
55 WaitForNavigateComplete(oIE)
56
57
58
59 '到第三个页面
60 Dim dropdown2,dropdown3
61 Set oForm = oIE.document.forms("aspnetForm")
62 Set dropdown1 = oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$dropdownValidationStatus")
63 Set dropdown2 = oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$dropdownSegment")
64 Set dropdown3 = oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$dropdownStatus")
65
66 Dim school,postal
67 Set school=oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$txtSchool")
68 Set postal=oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$ctl19")
69 Set button1 = oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$ctl96")
70 if(school(0).value=null Or Len(school(0).value)<=0) Then
71 school(0).value="NA"
72 end If
73 if(postal(0).value=null Or len(postal(0).value)<=0) Then
74 postal(0).value="NA"
75 end If
76
77 dropdown1(0).selectedIndex = 3
78 dropdown2(0).selectedIndex=1
79 dropdown3(0).selectedIndex=6
80 WScript.Sleep(5000)
81
82 button1(0).Click
83 WaitForNavigateComplete(oIE)
84
85 Call oIE.Quit()
86 Set oIE = Nothing
87
88
89
90 End Sub
91
92 ' --------------------------------------------------------------------
93 ' NavigateWait(InternetExplorer.Application, String)
94 ' --------------------------------------------------------------------
95 Private Sub NavigateWait(oIE, stUrl)
96 Call oIE.Navigate(stUrl)
97 Call WaitForNavigateComplete(oIE)
98 End Sub
99
100 ' --------------------------------------------------------------------
101 ' WaitForNavigateComplete(InternetExplorer.Application)
102 ' --------------------------------------------------------------------
103 Private Sub WaitForNavigateComplete(oIE)
104 Do While (oIE.busy)
105 Call WScript.Sleep(DELAY_TIME)
106 Loop
107
108 Do While (oIE.document.readyState <> "complete")
109 Call WScript.Sleep(DELAY_TIME)
110 Loop
111 End Sub
3 ' --------------------------------------------------------------------
4 ' Define
5 ' --------------------------------------------------------------------
6 Const DELAY_TIME = 200
7 Dim emailAddress, customerID
8 emailAddress = "meiweijun@163.com"
9 customerID = "N/A"
10 Call Main() '调用主函数
11
12 Private Sub Main()
13 Dim oIE 'As InternetExplorer.Application
14 Set oIE=CreateObject("InternetExplorer.Application")
15 oIE.Visible=True
16
17 Dim objWshShell '读取桌面文件夹
18 Set objWshShell = WScript.CreateObject("WScript.Shell")
19
20
21 ' read command line arguments
22 If WScript.Arguments.Count > 0 Then
23 emailAddress = WScript.Arguments.Item(0)
24 End If
25
26 '打开一个新的IE窗口
27 call NavigateWait(oIE,"about:blank")
28 objWshShell.AppActivate "about:blank"
29 WScript.Sleep(500)
30 call NavigateWait(oIE,"http://网址")
31 '输入Email地址并按下查询按钮
32 Dim oForm,dropdown1,inputbox1,button1
33 '获取表单
34 Set oForm=oIE.document.forms("aspnetForm")
35 '获取邮件下拉列表条件
36 set dropdown1=oIE.document.getElementsByName("ctl00$m$g_36d820b1_1932_42e6_b8a5_32d21fea0dab$ctl12")
37 '获取邮件文本框
38 Set inputbox1=oIE.document.getElementsByName("ctl00$m$g_36d820b1_1932_42e6_b8a5_32d21fea0dab$ctl13")
39 '获取查询按钮
40 Set button1 = oIE.document.getElementsByName("ctl00$m$g_36d820b1_1932_42e6_b8a5_32d21fea0dab$ctl74")
41 On Error Resume Next
42 dropdown1(0).selectedIndex=2 'email equals
43 if Err.Number>0 then
44 Call oIE.Quit()
45 Set oIE = Nothing
46 end If
47 inputbox1(0).value=emailAddress
48 button1(0).Click
49 WaitForNavigateComplete(oIE)
50
51 '到第二个页面
52 Set oForm = oIE.document.forms("aspnetForm")
53 Set button1 = oIE.document.getElementsByName("ctl00$m$g_4fdccc80_8665_4043_8b2d_264d342d4967$ctl01$ctl03$ctl00")
54 button1(0).Click
55 WaitForNavigateComplete(oIE)
56
57
58
59 '到第三个页面
60 Dim dropdown2,dropdown3
61 Set oForm = oIE.document.forms("aspnetForm")
62 Set dropdown1 = oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$dropdownValidationStatus")
63 Set dropdown2 = oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$dropdownSegment")
64 Set dropdown3 = oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$dropdownStatus")
65
66 Dim school,postal
67 Set school=oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$txtSchool")
68 Set postal=oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$ctl19")
69 Set button1 = oIE.document.getElementsByName("ctl00$m$g_9ff5ad08_cc4d_49ba_87be_8d05c894b88e$ctl96")
70 if(school(0).value=null Or Len(school(0).value)<=0) Then
71 school(0).value="NA"
72 end If
73 if(postal(0).value=null Or len(postal(0).value)<=0) Then
74 postal(0).value="NA"
75 end If
76
77 dropdown1(0).selectedIndex = 3
78 dropdown2(0).selectedIndex=1
79 dropdown3(0).selectedIndex=6
80 WScript.Sleep(5000)
81
82 button1(0).Click
83 WaitForNavigateComplete(oIE)
84
85 Call oIE.Quit()
86 Set oIE = Nothing
87
88
89
90 End Sub
91
92 ' --------------------------------------------------------------------
93 ' NavigateWait(InternetExplorer.Application, String)
94 ' --------------------------------------------------------------------
95 Private Sub NavigateWait(oIE, stUrl)
96 Call oIE.Navigate(stUrl)
97 Call WaitForNavigateComplete(oIE)
98 End Sub
99
100 ' --------------------------------------------------------------------
101 ' WaitForNavigateComplete(InternetExplorer.Application)
102 ' --------------------------------------------------------------------
103 Private Sub WaitForNavigateComplete(oIE)
104 Do While (oIE.busy)
105 Call WScript.Sleep(DELAY_TIME)
106 Loop
107
108 Do While (oIE.document.readyState <> "complete")
109 Call WScript.Sleep(DELAY_TIME)
110 Loop
111 End Sub
这样站点上的用户状态修改就可以无人值守的跑起来了
首先代码会打开网站,
并输入邮件地址,自动点击查询,到下一个页面
自动点击编辑,到下一个页面
自动修改状态为reject并点击保存按钮,整个IE退出。
能帮手工编辑的童鞋省很多事情啊