1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

痒いところに手が届く!vbsのスクリプトの忘備録!

Posted at

vbsのスクリプトを使ってみる。

エクスプローラー.vbs
Option Explicit
On Error Resume Next

Dim strFolderName   ' フォルダ名
Dim objShell        ' Shell オブジェクト

strFolderName = "C:\Temp"

Set objShell = WScript.CreateObject("Shell.Application")
If Err.Number = 0 Then
    objShell.Explore strFolderName
    WScript.Echo strFolderName & " を開きました。"
Else
    WScript.Echo "エラー: " & Err.Description
End If

Set objShell = Nothing
複数実行.vbs
Option Explicit
Dim objWshShell
'シェルオブジェクトの作成
Set objWshShell = WScript.CreateObject("WScript.Shell")
'シェルの実行
objWshShell.Run "C:\e.vbs"
IE複数起動.vbs
Option Explicit
    Dim objIE
 
    'オブジェクトの作成
    Set objIE = CreateObject("InternetExplorer.Application")
    
    'IEを表示させる。Trueで表示
    objIE.Visible = True 
 
    '指定したURLを開く
    objIE.Navigate2 "https://news.google.com/news/?edchanged=1&ned=jp&hl=ja"
    '新しいタブで表示
    objIE.Navigate2 "https://weather.yahoo.co.jp/weather/", &H800
    objIE.Navigate2 "https://transit.yahoo.co.jp/", &H800
ドラッグアンドドロップしたファイル名.vbs
Option Explicit        
 
    'ドラッグアンドドロップで取得したファイルパスを変数に入れる
    Dim GetPathArray
    Set GetPathArray = WScript.Arguments 
    
    'ファイルシステムオブジェクト
    Dim objFSO      
    Set objFSO = CreateObject("Scripting.FileSystemObject")              
    'イテレータ
    Dim pt
 
    'ファイルの数ぶんループする
    For Each pt in GetPathArray      
                        
        '取得したファイル名
        Dim FileName
        FileName = objFSO.GetFileName(pt)  
        
        'ファイルのフルパスをInputBoxで表示させる
        pt = InputBox("ドラッグアンドドロップしたファイル名 " & FileName,"ファイルのフルパスを表示", pt)        
    
    Next
    
    'オブジェクト変数をクリア
    Set objFSO = Nothing
VBScriptでWEBスクレイピング!テーブル要素を取得してCSVファイルで書き出す.vbs
Option Explicit
 
    Dim objIE
    Dim objLink
 
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Visible = True
 
    'IEを開く
     objIE.navigate "http://elze.tanosii.net/d/kenmei.htm"
     
    'ページが読み込まれるまで待つ
    Do While objIE.Busy = True Or objIE.readyState <> 4
        WScript.Sleep 100        
    Loop    
    
    
    Dim objTr,objTh,objTd       
    Dim el
    
    'tr要素をコレクションとして取得して変数にセット
    Set objTr = objIE.document.getElementsByTagName("tr")          
    
    'テーブル要素をcsvファイルに書き出す
    For each el In objTr
        
        If instr(el.outerhtml,"<th>") > 0 then
            Set objTh = el.getElementsByTagName("th")
            OutputText objTh(0).innerText & "," & objTh(1).innerText & "," & objTh(2).innerText
        Else
            Set objTd = el.getElementsByTagName("td")
            OutputText objTd(0).innerText & "," & objTd(1).innerText & "," & objTd(2).innerText         
        End If        
    next 
 
'テキストファイルへ出力
Function OutputText(ByVal strMsg)
 
    Dim objFSO
    Dim objText
    
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    Set objText = objFSO.OpenTextFile("C:\work\テーブル要素の書き出し結果.csv", 8, True)
 
    objText.write strMsg    
    objText.write vbCrLf
 
    objText.close
    
    Set objFSO = Nothing
    Set objText = Nothing 
 
End Function
    Set objFSO = Nothing
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?