カテゴリー
SugiBlog Webエンジニアのためのお役立ちTips

Excel VBA 画像の挿入

Sub auto_open()

    Dim myFileName As String
    Dim myShape As Shape

    myFileName = ActiveWorkbook.Path & "\sample.bmp"

    ' 選択位置に画像ファイルを挿入し、変数myShapeに格納
    Set myShape = ActiveSheet.Shapes.AddPicture( _
          Filename:=myFileName, _
          LinkToFile:=False, _
          SaveWithDocument:=True, _
          Left:=Selection.Left, _
          Top:=Selection.Top, _
          Width:=0, _
          Height:=0)

    ' 挿入した画像に対して元画像と同じ高さ・幅にする
    With myShape
        .ScaleHeight 1, msoTrue
        .ScaleWidth 1, msoTrue
    End With

End Sub

ACCESSからExcelを操作し、挿入する場合
続きを読む…»

12,045 views

正規表現の最短一致

正規表現の文字列検索にて、最短一致を検索します。
デフォルトは最長一致ですが、量指定子("*"、"+"、"{}"等)の後に"?"を付けることで最短一致に変更できます。

Visual Basic

Dim regEx As Object
Dim Matches As Variant

'正規表現オブジェクト
Set regEx = CreateObject("VBScript.RegExp")

続きを読む…»

17,366 views

Shell起動したアプリケーションの終了を待つ

Dim oShell As Object, oExec As Object

'オブジェクト変数に参照をセットします
Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.Exec("C:\example.exe")

'処理完了を待機
Do Until oExec.Status: DoEvents: Loop

'戻り値をセット
If Not oExec.StdErr.AtEndOfStream Then
	ExecCommand = True
	sResult = oExec.StdErr.ReadAll
ElseIf Not oExec.StdOut.AtEndOfStream Then
	sResult = oExec.StdOut.ReadAll
End If

'オブジェクト変数の参照を解放
Set oExec = Nothing: Set oShell = Nothing

'結果を表示
MsgBox sResult
8,077 views

アイコンの表示がおかしいとき

アイコンキャッシュのファイル「IconCache.db」を削除し、再起動します。

C:\Documents and Settings\Administrator\Local Settings\Application Data
2,543 views

レコードの検索【FindRecord】

DoCmd.FindRecord [FindWhat], [Match]

例1)

DoCmd.GoToControl "[検索するフィールドのコントロール]"
DoCmd.FindRecord "[検索する文字列]", [検索タイプ]

例2)

[検索するフィールドのコントロール].SetFocus
DoCmd.FindRecord "[検索する文字列]", [検索タイプ]

[検索タイプ]
acEntire=完全一致
acAnywhere=部分一致
acStart=検索文字列で始まる

5,802 views