アプリ版:「スタンプのみでお礼する」機能のリリースについて

こんにちは。
会社で写真台帳を作成しています。
以下のVBAだと横2列の写真台帳になりますが、
これを横3列の写真台帳にしたいと思っていますが、
どのようにすればよいのでしょうか?
このマクロは以前、会社にいた人が作ったらしいのですが、
その後退職してしまい、だれもマクロの内容が分からず困っています。
よろしくお願いします。

Sub 写真台帳()

Dim strFilter As String
Dim Filenames As Variant
Dim PIC As Picture

' 「ファイルを開く」ダイアログでファイル名を取得
strFilter = "画像ファイル(*.jpg;*.jpeg;*.gif;*.bmp;*.png),*.jpg;*.jpeg;*.gif;*.bmp;*.png"
Filenames = Application.GetOpenFilename( _
FileFilter:=strFilter, _
Title:="図の挿入(複数選択可)", _
MultiSelect:=True)
If Not IsArray(Filenames) Then Exit Sub

' ファイル名をソート
Call BubbleSort_Str(Filenames, True, vbTextCompare)

' 貼り付け開始セルを選択
Range("A5").Select

' マクロ実行中の画面描写を停止
Application.ScreenUpdating = False
' 順番に画像を挿入
j = -1

For i = LBound(Filenames) To UBound(Filenames)

j = j + 1




Set PIC = ActiveSheet.Pictures.Insert(Filenames(i))

'-------------------------------------------------------------
' 画像の各種プロパティ変更
'-------------------------------------------------------------
With PIC
.Top = ActiveCell.Top ' 位置:アクティブセルの上側に重ねる
.Left = ActiveCell.Left ' 位置:アクティブセルの左側に重ねる
.Placement = xlMove ' 移動するがサイズ変更しない
.PrintObject = True ' 印刷する
End With
With PIC.ShapeRange
.LockAspectRatio = msoTrue ' 縦横比維持
' 画像の幅をアクティブセルにあわせる
' 結合セルの場合でも対応
.Width = ActiveCell.MergeArea.Width 'Height:高さに合わせる場合
End With

' 次の貼り付け先を選択(アクティブセルにする)[例:5個下のセル]



If j Mod 2 = 0 Then

ActiveCell.Offset(0, 1).Select


Else
ActiveCell.Offset(4, -1).Select

End If



Set PIC = Nothing
Next i

' 終了
Application.ScreenUpdating = True
MsgBox i - 1 & "枚の画像を挿入しました", vbInformation

End Sub

' バブルソート(文字列)
Private Sub BubbleSort_Str( _
ByRef Source As Variant, _
Optional ByVal SortAsc As Boolean = True, _
Optional ByVal Compare As VbCompareMethod = vbTextCompare)

If Not IsArray(Source) Then Exit Sub

Dim i As Long, j As Long
Dim vntTmp As Variant
For i = LBound(Source) To UBound(Source) - 1
For j = LBound(Source) To LBound(Source) + UBound(Source) - i - 1
If StrComp(Source(IIf(SortAsc, j, j + 1)), _
Source(IIf(SortAsc, j + 1, j)), Compare) = 1 Then
vntTmp = Source(j)
Source(j) = Source(j + 1)
Source(j + 1) = vntTmp
End If
Next j
Next i

End Sub

A 回答 (1件)

変更場所は下記2点です。


> If j Mod 2 = 0 Then
→ If j Mod 3 <> 2 Then

> ActiveCell.Offset(4, -1).Select
→ ActiveCell.Offset(4, -2).Select
    • good
    • 0
この回答へのお礼

ありがとうございました。なんとかできました。

もうひとつあるのですが、画像をセルの真ん中に貼り付けるときはどのようにすればよいのでしょうか?
引き続きよろしくお願いします。

お礼日時:2009/05/15 15:55

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!