dポイントプレゼントキャンペーン実施中!

お世話になっております。。。
excel2007です。
アクティブである、ThisWorkbookに
外部ファイルから値のみ取得し、ThisWorkbookのA14セルからA27まで
入力させたい・・・
のですが、上手くいきません。
WEB検索して、ExecuteExcel4Macroでやってみたのですが、
Cells(1, C + 13) = ExecuteExcel4Macro("'strFullPath1'!受注書" & "Cells(2, C + 23)")
のところで、「値の更新:strFullPath1」と出てしまいます。
どうしたら良いでしょうか?


Private Sub CommandButton1_Click()
Const FILE_DIR1 As String = "\\192.168.~" '途中までのパス
Const FILE_DIR2 As String = "\\192.168.~~" '途中までのパス

Dim strFullPath1 As String
Dim strFullPath2 As String
Dim strFileName As String
Dim フォルダ名 As String
Dim C As Integer

フォルダ名 = TextBox2.Value & "\" & Range("B4") & "\"
strFileName = "*" & Range("B5") & " " & Range("B6") & ".xls"
strFullPath1 = FILE_DIR1 & フォルダ名 & strFileName
strFullPath2 = FILE_DIR2 & フォルダ名 & strFileName
C = 1

If Dir(strFullPath1) <> "" Then
For C = 1 To 14
Cells(1, C + 13) = ExecuteExcel4Macro("'strFullPath1'!受注書" & "Cells(2, C + 23)")
Next D
Else
For C = 1 To 14
Cells(1, C + 13).Formula = "[strFullPath2]sheet!cells(1,D+17)"
Cells(1, C + 13).Value = Cells(D, 14).Value
Next D
End If
Unload Me
End Sub

端折っているので、抜けがあるかもしれません。
お知恵を頂けますでしょうか?
宜しくお願い致します。

A 回答 (2件)

こんにちは。



>strFileName = "*" & Range("B5") & " " & Range("B6") & ".xls"

* は、ファイル・フルネームには使えません。ワイルドカードです。
ブック名は、[] で囲みます。

ネットワークではありませんが、このようなスタイルになります。
ExecuteExcel4Macro の中は、R1C1 型で書きます。

'--------------------------------------

FILE_DIR1 = "C:\"
フォルダ名 = "Documents and Settings\[Test 1]\My Documents\"
strFileName = "[Test1.xls]"

strFullPath1 = FILE_DIR1 & フォルダ名 & strFileName

i = 1
j = 1

Cells(1, i + 13).Value = ExecuteExcel4Macro("'" & strFullPath1 & "受注書'!" & "R" & i & "C" & j)
    • good
    • 0

Cells(2, C + 23)を""で囲ってる時点でおかしいです。


アドレスはR1C1形式で指定しないと駄目です。
それと、'strFullPath1'!がシート名?

不明な点が多いので、直接の回答は控えますが、以下のURLが参考になると思います。

http://www.officetanaka.net/excel/vba/tips/tips2 …
    • good
    • 0

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