添付ファイル フィールドにファイルがある場合、VBA を使用してファイル名を文字列として取得するにはどうすればよいですか? それらはExcelファイルなので、次のようなことをしたいです:
xlApp.Workbooks.Open("M:\strFilename.xlsx")
添付ファイル フィールドにファイルがある場合、VBA を使用してファイル名を文字列として取得するにはどうすればよいですか? それらはExcelファイルなので、次のようなことをしたいです:
xlApp.Workbooks.Open("M:\strFilename.xlsx")
私は、あなたが探しているものを達成すると信じているこのAccess ブログを見つけました。基本的に、ファイルのコピーを %temp% ディレクトリに保存して開きます。
有用な抜粋:
Public Function TestOpenFirstAttachmentAsTempFile()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Const strTable = "Table1"
Const strField = "Files" ' Attachment field in Table1
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strTable)
'rst.MoveNext ' Uncomment this line to go to the 2nd row in the Table.
OpenFirstAttachmentAsTempFile rst, strField
rst.Close
End Function
Public Function OpenFirstAttachmentAsTempFile(ByRef rstCurrent As DAO.Recordset, ByVal strFieldName As String) As String
Dim rstChild As DAO.Recordset2
Dim fldAttach As DAO.Field2
Dim strFilePath As String
Dim strTempDir As String
strTempDir = Environ("Temp") ' Get the Temp directory from the environment variable.
If Right(strTempDir, 1) <> "\" Then strTempDir = strTempDir & "\" ' Make sure the path always ends with a backslash.
Set rstChild = rstCurrent.Fields(strFieldName).Value ' the .Value for a complex field returns the underlying recordset.
strFilePath = strTempDir & rstChild.Fields("FileName").Value ' Append the name of the first (and only) attached file to temp dir.
If Dir(strFilePath) <> "" Then ' the file already exists--delete it first.
VBA.SetAttr strFilePath, vbNormal ' remove any file attributes (e.g. read-only) that would block the kill command.
VBA.Kill strFilePath ' delete the file.
End If
Set fldAttach = rstChild.Fields("FileData") ' The binary data of the file.
fldAttach.SaveToFile strFilePath
rstChild.Close ' cleanup
VBA.Shell "Explorer.exe " & Chr(34) & strFilePath & Chr(34), vbNormalFocus ' Use Windows Explorer to launch the file.
End Function 'OpenFirstAttachmentAsTempFile