根据查询重命名VBA中的文件 [英] Rename files from VBA based on a query

查看:77
本文介绍了根据查询重命名VBA中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

所有的拳头,抱歉我的英语不好。


我有一个包含大量文章的数据库。每篇文章都有一个图像,但此图像存储在名为c:\Images的文件夹中。现在我需要根据表的字段值将所有图像重命名为新名称。即:表文章:字段:OldName,Newname。然后我必须将所有文件,oldname1.jpg,oldname2.jpg等重命名或复制到另一个路径到newname1.jpg,newname2.jpg等。


我想知道是否可能用VBA做这个。

提前致谢。


Jose

解决方案

使用oldschool (324.1 KB,161 views)


Hi all,
Fist of all, sorry for my bad English.

I have a database with a lot of articles. Each article has an image, but this image is stored in a folder called c:\Images. Now I need to rename all the images to a new name based in a field value of the table. i.e.: Table Articles: Fields: OldName, Newname. Then I have to rename or copy to another path all files, oldname1.jpg, oldname2.jpg, etc to newname1.jpg, newname2.jpg, etc.

I wonder if is possible to make this with VBA.
Thanks in advance.

Jose

解决方案

Use the oldschool NAME() (click me (^_^) )

You may find this article handy too: http://bytes.com/topic/access/insigh...i-o-statements


BTW: This is one reason one should not use "Name," "Dir," "Date," etc.. as field names:
Access 2007 reserved words and symbols
AllenBrowne- Problem names and reserved words in Access


The basic concept is as follows:

  1. Create a Recordset based on the Articles Table.
  2. Loop thru the Recordset and determine if the [OldName] Field is NULL, if it is skip this Record.
  3. If the [OldName] Field is not NULL, see if the File exists in the C:\Images Path and that the [NewName] Field is not NULL.
  4. Assuming both conditions are True, copy the File [OldFile] to the same Folder renaming it [NewFile]
  5. Demo Code follows to get you started, any questions feel free to ask.

    Expand|Select|Wrap|Line Numbers


Hi,

I''ve made your solution but nothing happens. If you want, I send you a example db with some photos to try.

Thanks a lot.

Regards.

Jose.

Attached Files
Images.zip (324.1 KB, 161 views)


这篇关于根据查询重命名VBA中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆