![見出し画像](https://assets.st-note.com/production/uploads/images/99945360/rectangle_large_type_2_f0d912bae9bf176f0e9c796870f69205.jpeg?width=1200)
016_質問:【自己責任】AIさん助けて、マクロ3つ作って(涙)
仕事が、仕事が終わらないのだ。
土曜になのに、すでに頭が月曜日。
AIさん、お願いします。
仕事に欲しいマクロ
●複数のエクセルファイルにパスワードをかける
●複数のエクセルファイルの形式を.xlsxから.xlsに別名保存するマクロ
●ワードの表で、特定の文字がある行を一行ごと黄色く塗りつぶすマクロ
今回の質問形式
こんにちは、今日はExcel関係の質問です。
日本語で質問しますので、以下の形式で回答してください。
質問1
1.【今回の質問・またはお願い】
Excelファイルがたくさん入っているフォルダがあります。
そのフォルダに入っているExcelファイルすべてに、パスワードをつけて保存するマクロを作ってください。
2.【質問の英訳】
3.【英訳に対する英語の回答】
4.【英語の回答の日本語訳】
質問2
1.【今回の質問・またはお願い】
Excelファイルがたくさん入っているフォルダがあります。
そのフォルダに入っているExcelファイルをすべて.xlsxから.xlsに別名保存するマクロを作ってください。
2.【質問の英訳】
3.【英訳に対する英語の回答】
4.【英語の回答の日本語訳】
質問3
1.【今回の質問・またはお願い】
Excelデータを差し込んだwordのデータがあります。
wordのデータは表になっています。
表の中に特定の文字があった場合、その文字があった行を一行ごと蛍光ペンの黄色で塗りつぶすマクロを作ってください。
2.【質問の英訳】
3.【英訳に対する英語の回答】
4.【英語の回答の日本語訳】
AI回答
1.【今回の質問・またはお願い】
Excelファイルがたくさん入っているフォルダがあります。
そのフォルダに入っているExcelファイルすべてに、パスワードをつけて保存するマクロを作ってください。
2.【質問の英訳】
I have a folder containing many Excel files, and I would like to create a macro that adds a password to and saves all of the Excel files in that folder.
3.【英訳に対する英語の回答】
Here is a VBA code that should do what you are asking for:
……まだコードが零れ落ちている↓
vbnet
Sub PasswordProtect()
Dim folderPath As String
Dim currentFile As String
Dim password As String
folderPath = "C:\ExampleFolderPath\" 'replace with your folder path
password = "ExamplePassword" 'replace with your desired password
currentFile = Dir(folderPath & "*.xlsx")
Do While currentFile <> ""
Workbooks.Open folderPath & currentFile
ActiveWorkbook.Password = password
ActiveWorkbook.Save
ActiveWorkbook.Close
currentFile = Dir
Loop
End Sub
4.【英語の回答の日本語訳】
以下は、お望みの動作を行うVBAコードです:
↓手動でつけなおしました。
Sub PasswordProtect()
Dim folderPath As String
Dim currentFile As String
Dim password As String
folderPath = "C:\ExampleFolderPath\" 'フォルダパスを指定してください
password = "ExamplePassword" 'パスワードを指定してください
currentFile = Dir(folderPath & "*.xlsx")
Do While currentFile <> ""
Workbooks.Open folderPath & currentFile
ActiveWorkbook.Password = password
ActiveWorkbook.Save
ActiveWorkbook.Close
currentFile = Dir
Loop
End Sub
上記コードをExcelのVBAエディタで新しいモジュールに貼り付けてください。また、フォルダパスとパスワードを適切なものに変更してください。その後、マクロを実行すると、指定したフォルダに保存されているすべてのExcelファイルにパスワードが設定され、保存されます。
AI回答2
1.【今回の質問・またはお願い】
Excelファイルがたくさん入っているフォルダがあります。
そのフォルダに入っているExcelファイルをすべて.xlsxから.xlsに別名保存するマクロを作ってください。
2.【質問の英訳】
I have a folder containing many Excel files, and I would like to create a macro that saves all of the Excel files in that folder as .xls files with a different name.
3.【英訳に対する英語の回答】
Here is a VBA code that should do what you are asking for:
Sub ConvertToXLS()
Dim folderPath As String
Dim currentFile As String
Dim newFileName As String
folderPath = "C:\ExampleFolderPath\" 'フォルダパスを指定してください
currentFile = Dir(folderPath & "*.xlsx")
Do While currentFile <> ""
newFileName = Replace(currentFile, ".xlsx", ".xls")
Workbooks.Open folderPath & currentFile
ActiveWorkbook.SaveAs folderPath & newFileName, FileFormat:=xlExcel8
ActiveWorkbook.Close
currentFile = Dir
Loop
End Sub
4.【英語の回答の日本語訳】
以下は、お望みの動作を行うVBAコードです:
……上下ともコードをつけ直しました。
Sub ConvertToXLS()
Dim folderPath As String
Dim currentFile As String
Dim newFileName As String
folderPath = "C:\ExampleFolderPath\" 'フォルダパスを指定してください
currentFile = Dir(folderPath & "*.xlsx")
Do While currentFile <> ""
newFileName = Replace(currentFile, ".xlsx", ".xls")
Workbooks.Open folderPath & currentFile
ActiveWorkbook.SaveAs folderPath & newFileName, FileFormat:=xlExcel8
ActiveWorkbook.Close
currentFile = Dir
Loop
End Sub
上記コードをExcelのVBAエディタで新しいモジュールに貼り付けてください。また、フォルダパスを適切なものに変更してください。その後、マクロを実行すると、指定したフォルダに保存されているすべてのExcelファイルが.xlsxから.xlsに別名保存されます。
AI回答3
1.【今回の質問・またはお願い】
Excelデータを差し込んだwordのデータがあります。
wordのデータは表になっています。
表の中に特定の文字があった場合、その文字があった行を一行ごと蛍光ペンの黄色で塗りつぶすマクロを作ってください。
2.【質問の英訳】
I have a Word document with a table that contains data from an Excel file. I would like to create a macro that highlights entire rows in the table where a specific text is found with a yellow highlighter.
3.【英訳に対する英語の回答】
Here's a VBA code that should do what you are asking for:
Sub HighlightRows()
Dim targetText As String
targetText = "目標のテキスト" '目標のテキストに置き換えてください
Dim tbl As Table
For Each tbl In ActiveDocument.Tables
Dim r As Row
For Each r In tbl.Rows
Dim c As Cell
For Each c In r.Cells
If InStr(1, c.Range.Text, targetText) > 0 Then
r.Range.HighlightColorIndex = wdYellow
Exit For
End If
Next c
Next r
Next tbl
End Sub
4.【英語の回答の日本語訳】
以下は、お望みの動作を行うVBAコードです:
Sub HighlightRows()
Dim targetText As String
targetText = "目標のテキスト" '目標のテキストに置き換えてください
Dim tbl As Table
For Each tbl In ActiveDocument.Tables
Dim r As Row
For Each r In tbl.Rows
Dim c As Cell
For Each c In r.Cells
If InStr(1, c.Range.Text, targetText) > 0 Then
r.Range.HighlightColorIndex = wdYellow
Exit For
End If
Next c
Next r
Next tbl
End Sub
上記コードをWordのVBAエディタで新しいモジュールに貼り付けてください。その後、マクロを実行すると、表の中に目標のテキストがある行が蛍光ペンの黄色で強調表示されます。
![](https://assets.st-note.com/img/1678452311920-p4LL0aDRJu.png?width=1200)
AIくんにマクロを作ってもらっている。(遠い目)