2
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 Excelファイルのパスワードを解除し、パスワードがなければパスワードをかける

Posted at

スクリプト

OpenxlWorkBooks.VBS
Option Explicit
'Excel 2013 Later Japenese Version Available
'REF: 
'REF: 
'''///---定数の設定Set Enumuragion---///'''
Const PWD="PASS"
Const msoLanguageIDInstall = 1
'''///---変数の宣言---///'''
 Dim objArgs, I , strFile
 Dim objFile, objFolder,objPath,strScr
 Dim xlApp,Wb
 Dim objWShell : Set objWShell = Createobject("WScript.Shell")
 Dim FSO : Set FSO = Createobject("Scripting.FileSystemObject")

'''///---ファイル処理開始 Start Document File Conversion---///'''
Set objArgs = Wscript.Arguments
For I = 0 to objArgs.Count-1
  set objFile = FSO.GetFile(cstr(objArgs(I)))
   If Lcase(Left(FSO.GetExtensionName(objFile.Path) ,3) )="xls" Then
     Set xlApp =CreateObject("Excel.Application")
     If xlApp.Version < 14 Then xlApp.Quit: Set xlApp = Nothing:wscript.Quit
     xlApp.DisplayAlerts=False
     xlApp.Visible = True
     set wb=xlapp.WorkBooks.Open(objFile.Path,0,false,,PWd,,True,,false,false,,true,true)
     if wb.HasPassword=true then
        wb.Saveas objFile.Path,,"","",False
     else
        wb.Saveas objFile.Path,,Pwd,"",False
     End if
     wb.close
     set wb=nothing
   End If
Next
xlApp.DisplayAlerts=True
xlApp.Quit
set xlApp = Nothing

注意点

閉じたExcelのパスワードを判定する

閉じているエクセルファイルがパスワードで保護されているか、を見分ける関数
本当はこれをVBSにしたかったけどちょっと複雑なので手を抜きました。

2
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
2
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?