カテゴリー
SugiBlog Webデザイナー・プログラマーのためのお役立ちTips

ACCESS Excelオートメーションメモ

Dim xlApp   As Object
Dim xlBook  As Object
Dim xlSheet As Object

Dim FileName   As String
Dim myFileName As String
Dim myShape    As Object

FileName = Environ("USERPROFILE") & "\デスクトップ\sample.xls"

Set xlApp   = CreateObject("Excel.Application")
Set xlBook  = xlApp.Workbooks.Add
Set xlSheet = xlBook.WorkSheets(1)

With xlSheet

    .Range("A18:D18").MergeCells = True       'セルを結合
    .Range("A18").HorizontalAlignment = -4108 '横位置を中央揃えに
    .Range("A18").Font.Size = 48              'フォントの大きさを変更

End With

'保存
xlBook.Saveas (FileName)

xlBook.Close

xlApp.Application.Quit

Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
3,141 views

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を操作し、挿入する場合
続きを読む…»

11,836 views

正規表現の最短一致

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

Visual Basic

Dim regEx As Object
Dim Matches As Variant

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

続きを読む…»

16,688 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
6,851 views

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

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

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