|
▼ちゃっぴ さん:
>> GetOpenFilenameはMultiSelectをTrueにするとファイル名の
>> バリアント型の配列を返します。
>
>> 従って、「For 〜 Nextステートメント」か「For Each 〜 Nextステートメント」
>> で配列を一件ずつループしてやる必要があります。
>
>ということなので
>
>Dim vntFilename As Variant
>
>For Each vntFilename In FileToOpen
> Workbooks.Open vntFilename
>Next vntFilename
>
>のようにしてみてください。
>ヘルプで「For Each...Next ステートメントの使い方」を参照してみてください。
▼ちゃっぴ さん
出来ました!どうもありがとうございます。
そこで当初の質問に戻るのですが、その選択したファイルからデータをコピーして
別ファイルに出力するようにしたいのです。
お手数おかけしますが引き続きお願いします。
コピーして別ファイルに出力するソースを公開します。
Const INBOOK As String = "Book1.xls"
Const INSHEET As String = "insheet1"
Const OUTBOOK As String = "Book3.xls"
Const OUTSHEET As String = "outsheet1"
Const INSHEET2 As String = "insheet2"
Private Sub CommandButton1_Click()
Workbooks(INBOOK).Worksheets(INSHEET).Range("D40,F40:K40,O40,AM40").Copy
Workbooks("Book3.xls").Worksheets("Sheet2").Range("B2").PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks(INBOOK).Worksheets(INSHEET2).Range("M4,AT4,AU4,BB4,BC4,BD4,BE4").Copy
Workbooks("Book3.xls").Worksheets("Sheet2").Range("B4").PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(2, 2).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(3, 19).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(2, 3).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 6).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(2, 4).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 7).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(2, 5).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 9).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(2, 6).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 10).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(2, 7).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 12).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(2, 9).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 13).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(2, 10).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(14, 4).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(4, 2).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(38, 11).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(4, 3).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 18).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(4, 4).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 19).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(4, 5).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 2).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(4, 6).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 3).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(4, 7).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 20).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Workbooks("Book3.xls").Worksheets("Sheet2").Cells(4, 8).Copy
Workbooks(OUTBOOK).Worksheets(OUTSHEET).Cells(6, 21).PasteSpecial xlPasteAll
Application.CutCopyMode = False
MsgBox "終了・・・"
End Sub
|
|