JW-CADの紹介・牛丼チャンネル

gooブログで
JW-CADによる建築CAD検定の解答例の
紹介を始めました

エクセル・EXCEL・VBA・マクロで息抜き・牛丼チャンネル

2022-07-30 01:06:16 | エクセル

エクセルのモジュールに以下のテキスト貼り付けると動きます。

Sub ナイトライダー()


Dim i As Integer
Dim ii As Integer
Dim 行 As Integer
Dim 列 As Integer
Dim 繰り返し幅 As Integer
Dim 繰り返し数 As Integer


繰り返し数 = 5
繰り返し幅 = 7
行 = 20
列 = 9

Range("A1").Select


With Cells
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
.Interior.ThemeColor = xlThemeColorLight1
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With

With Range(Cells(行, 列), Cells(行, 列 + 繰り返し幅))
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).ThemeColor = 2
.Borders(xlEdgeLeft).TintAndShade = 0.499984740745262
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).ThemeColor = 2
.Borders(xlEdgeTop).TintAndShade = 0.499984740745262
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).ThemeColor = 2
.Borders(xlEdgeBottom).TintAndShade = 0.499984740745262
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).ThemeColor = 2
.Borders(xlEdgeRight).TintAndShade = 0.499984740745262
.Borders(xlEdgeRight).Weight = xlThin
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideVertical).ThemeColor = 2
.Borders(xlInsideVertical).TintAndShade = 0.499984740745262
.Borders(xlInsideVertical).Weight = xlThin
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With




Range(Cells(行, 列), Cells(行, 列 + 繰り返し幅)).Interior.Color = 255

Application.Wait [Now() + "00:00:01"]

ライト

Application.Wait [Now() + "00:00:01"]

Range(Cells(行, 列), Cells(行, 列 + 繰り返し幅)).Interior.Color = xlSolid

Application.Wait [Now() + "00:00:01"]



Cells(行, 列).Interior.Color = 255


Application.Wait [Now() + "00:00:00.7"]

Cells(行, 列).Interior.Color = 0


For ii = 1 To 繰り返し数 - 4

For i = 1 To 繰り返し幅

Cells(行, 列 + 1).Interior.Color = 255

Application.Wait [Now() + "00:00:00.7"]

Cells(行, 列 + 1).Interior.Color = 0

列 = 列 + 1

Next



For i = 1 To 繰り返し幅

Cells(行, 列 - 1).Interior.Color = 255

Application.Wait [Now() + "00:00:00.7"]

Cells(行, 列 - 1).Interior.Color = 0

列 = 列 - 1

Next

Next



For ii = 1 To 繰り返し数 - 3

For i = 1 To 繰り返し幅

Cells(行, 列 + 1).Interior.Color = 255

Application.Wait [Now() + "00:00:00.4"]

Cells(行, 列 + 1).Interior.Color = 0

列 = 列 + 1

Next



For i = 1 To 繰り返し幅

Cells(行, 列 - 1).Interior.Color = 255

Application.Wait [Now() + "00:00:00.4"]

Cells(行, 列 - 1).Interior.Color = 0

列 = 列 - 1

Next

Next



For ii = 1 To 繰り返し数 - 2

For i = 1 To 繰り返し幅

Cells(行, 列 + 1).Interior.Color = 255

Application.Wait [Now() + "00:00:00.2"]

Cells(行, 列 + 1).Interior.Color = 0

列 = 列 + 1

Next



For i = 1 To 繰り返し幅

Cells(行, 列 - 1).Interior.Color = 255

Application.Wait [Now() + "00:00:00.2"]

Cells(行, 列 - 1).Interior.Color = 0

列 = 列 - 1

Next

Next



For ii = 1 To 繰り返し数

For i = 1 To 繰り返し幅

Cells(行, 列 + 1).Interior.Color = 255

Application.Wait [Now() + "00:00:00.08"]

Cells(行, 列 + 1).Interior.Color = 0

列 = 列 + 1

Next



For i = 1 To 繰り返し幅

Cells(行, 列 - 1).Interior.Color = 255

Application.Wait [Now() + "00:00:00.08”]

Cells(行, 列 - 1).Interior.Color = 0

列 = 列 - 1

Next

Next

Range(Cells(行, 列), Cells(行, 列 + 繰り返し幅)).Interior.Color = 255

Application.Wait [Now() + "00:00:01"]

Range(Cells(行, 列), Cells(行, 列 + 繰り返し幅)).Interior.Color = 300


ライト消灯

Application.Wait [Now() + "00:00:01"]

With Cells
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
.Interior.ThemeColor = xlThemeColorLight1
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With

With Cells
.Interior.Pattern = xlNone
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With

Application.Wait [Now() + "00:00:01"]

With Cells
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With




End Sub
Sub ライト()


iiii = 20

For iii = 1 To 7
With Range(Cells(iiii, 4), Cells(20, 6))
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).ColorIndex = 0
.Borders(xlEdgeLeft).TintAndShade = 0
.Borders(xlEdgeLeft).Weight = xlThin

.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).ColorIndex = 0
.Borders(xlEdgeTop).TintAndShade = 0
.Borders(xlEdgeTop).Weight = xlThin

.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).ColorIndex = 0
.Borders(xlEdgeBottom).TintAndShade = 0
.Borders(xlEdgeBottom).Weight = xlThin

.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).ColorIndex = 0
.Borders(xlEdgeRight).TintAndShade = 0
.Borders(xlEdgeRight).Weight = xlThin

.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
.Interior.ThemeColor = xlThemeColorDark1
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With

With Range(Cells(iiii, 19), Cells(20, 21))
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).ColorIndex = 0
.Borders(xlEdgeLeft).TintAndShade = 0
.Borders(xlEdgeLeft).Weight = xlThin

.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).ColorIndex = 0
.Borders(xlEdgeTop).TintAndShade = 0
.Borders(xlEdgeTop).Weight = xlThin

.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).ColorIndex = 0
.Borders(xlEdgeBottom).TintAndShade = 0
.Borders(xlEdgeBottom).Weight = xlThin

.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).ColorIndex = 0
.Borders(xlEdgeRight).TintAndShade = 0
.Borders(xlEdgeRight).Weight = xlThin

.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
.Interior.ThemeColor = xlThemeColorDark1
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With

iiii = iiii - 1

Application.Wait [Now() + "00:00:00.05"]

Next

End Sub


Sub ライト消灯()


iiii = 14

For iii = 1 To 7
With Range(Cells(iiii, 4), Cells(20, 6))
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).ColorIndex = 0
.Borders(xlEdgeLeft).TintAndShade = 0
.Borders(xlEdgeLeft).Weight = xlThin

.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).ColorIndex = 0
.Borders(xlEdgeTop).TintAndShade = 0
.Borders(xlEdgeTop).Weight = xlThin

.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).ColorIndex = 0
.Borders(xlEdgeBottom).TintAndShade = 0
.Borders(xlEdgeBottom).Weight = xlThin

.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).ColorIndex = 0
.Borders(xlEdgeRight).TintAndShade = 0
.Borders(xlEdgeRight).Weight = xlThin

.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
.Interior.ThemeColor = xlThemeColorDark1
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With
With Range(Cells(iiii, 4), Cells(iiii, 6))
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
.Interior.ThemeColor = xlThemeColorLight1
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With

With Range(Cells(iiii, 19), Cells(20, 21))
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).ColorIndex = 0
.Borders(xlEdgeLeft).TintAndShade = 0
.Borders(xlEdgeLeft).Weight = xlThin

.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).ColorIndex = 0
.Borders(xlEdgeTop).TintAndShade = 0
.Borders(xlEdgeTop).Weight = xlThin

.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).ColorIndex = 0
.Borders(xlEdgeBottom).TintAndShade = 0
.Borders(xlEdgeBottom).Weight = xlThin

.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).ColorIndex = 0
.Borders(xlEdgeRight).TintAndShade = 0
.Borders(xlEdgeRight).Weight = xlThin

.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
.Interior.ThemeColor = xlThemeColorDark1
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With
With Range(Cells(iiii, 19), Cells(iiii, 21))
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
.Interior.ThemeColor = xlThemeColorLight1
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With

iiii = iiii + 1

Application.Wait [Now() + "00:00:00.05"]

Next

End Sub




エクセルでChromeを操作して、YAHOOトップページを開く

2022-03-19 16:00:44 | エクセル


エクセル・EXCEL・SeleniumBasic・WebDriver・準備・YAHOOトップページを開く・牛丼チャンネル


1:SeleniumBasicをダウンロードして、インストールします

1-1:検索キーワード【 SeleniumBasic 】で検索します


1-2:SeleniumBasic -GitHub Pagesを開きます

1-3:下へスクロールします

1-4:ダウンロードの【 リリースページ 】を開きます

1-5:SeleniumBasic-2.0・・・.exeを任意のフォルダに保存します


1-6:保存したファイルを開きます

1-7:画面の指示に従ってインストールします



※使用しているブラウザのみチェックします




2:使用しているChromeのバージョンに合わせた
 WebDriverをダウンロードして、
 【 C:\Users\"ユーザー名"\AppData\Local\SeleniumBasic\ 】内の
 ファイルを上書き(置き換え)します

2-1:検索キーワード【 WebDriver Chrome 】で検索します


2-2:Chromeのバージョンを確認します








2-3:ChromeDriver ‐ WebDriver for Chrome - Downloadsを開きます

2-4:下へスクロールします


2-5:ChromeDriver 99.0.4844.51を開きます。(下二桁違いますが・・・)

2-6:ChromeDriver Win32.zipをダウンロードします


2-7:任意のフォルダに保存します


2-8:フォルダを開きます


2-9:zipファイルを開きます


2-10:.exeファイルをコピーします




2-11:隠しフォルダを表示します









2-12:【 C:\Users\"ユーザー名"\AppData\Local\SeleniumBasic\ 】を開きます










2-13:貼り付けします


2-14:ファイルを置き換えします





3:エクセルの準備をします


3-1:ツールバーに開発タブを表示します






3-2:開発タブをクリックします


3-3:Visual Basicを開きます


3-4:ツール-参照設定






3-5:【 Selenium Type library】にチェックを入れます


3-6:標準モジュールを挿入します




3-7:ファイル形式を【 xlsm 】として保存します





3-8:Yahooトップページを開くコードを入力します


Dim Driver As New Selenium.WebDriver

Sub ヤフーを開く()

'chromeを起動します。
Driver.Start "chrome"

'YAHOOのサイトを開きます。
Driver.Get "https://www.yahoo.co.jp/"

End Sub